visualvault-api 1.2.0 → 2.0.0-beta.2

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.
Files changed (45) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +23 -140
  3. package/dist/VVRestApi.cjs +2552 -0
  4. package/dist/VVRestApi.cjs.map +1 -0
  5. package/dist/VVRestApi.d.cts +386 -0
  6. package/dist/VVRestApi.d.ts +386 -0
  7. package/dist/VVRestApi.js +2522 -0
  8. package/dist/VVRestApi.js.map +1 -0
  9. package/{lib/VVRestApi/VVRestApiNodeJs → dist}/config.yml +3 -3
  10. package/dist/constants.cjs +45 -0
  11. package/dist/constants.cjs.map +1 -0
  12. package/dist/constants.d.cts +48 -0
  13. package/dist/constants.d.ts +48 -0
  14. package/dist/constants.js +20 -0
  15. package/dist/constants.js.map +1 -0
  16. package/dist/index.cjs +2572 -0
  17. package/dist/index.cjs.map +1 -0
  18. package/dist/index.d.cts +2 -0
  19. package/dist/index.d.ts +2 -0
  20. package/dist/index.js +2541 -0
  21. package/dist/index.js.map +1 -0
  22. package/package.json +46 -70
  23. package/lib/VVRestApi/VVRestApiNodeJs/DocApi.js +0 -66
  24. package/lib/VVRestApi/VVRestApiNodeJs/FormsApi.js +0 -51
  25. package/lib/VVRestApi/VVRestApiNodeJs/NotificationsApi.js +0 -39
  26. package/lib/VVRestApi/VVRestApiNodeJs/ObjectsApi.js +0 -138
  27. package/lib/VVRestApi/VVRestApiNodeJs/StudioApi.js +0 -156
  28. package/lib/VVRestApi/VVRestApiNodeJs/VVRestApi.js +0 -1974
  29. package/lib/VVRestApi/VVRestApiNodeJs/app.js +0 -128
  30. package/lib/VVRestApi/VVRestApiNodeJs/common.js +0 -1598
  31. package/lib/VVRestApi/VVRestApiNodeJs/dts/express.d.ts +0 -125
  32. package/lib/VVRestApi/VVRestApiNodeJs/dts/node.d.ts +0 -1090
  33. package/lib/VVRestApi/VVRestApiNodeJs/files/237de37cf014ee1199a400d49e26e066.js +0 -51
  34. package/lib/VVRestApi/VVRestApiNodeJs/files/437833dc404aed118b0e644bf02b9c8a.js +0 -1
  35. package/lib/VVRestApi/VVRestApiNodeJs/log.js +0 -20
  36. package/lib/VVRestApi/VVRestApiNodeJs/public/favicon.ico +0 -0
  37. package/lib/VVRestApi/VVRestApiNodeJs/routes/scheduledscripts.js +0 -203
  38. package/lib/VVRestApi/VVRestApiNodeJs/routes/scripts.js +0 -215
  39. package/lib/VVRestApi/VVRestApiNodeJs/routes/testScheduledScripts.js +0 -131
  40. package/lib/VVRestApi/VVRestApiNodeJs/samples/SampleScheduledScript.js +0 -90
  41. package/lib/VVRestApi/VVRestApiNodeJs/samples/SendEmailScript.js +0 -51
  42. package/lib/VVRestApi/VVRestApiNodeJs/samples/fileTest.js +0 -60
  43. package/lib/VVRestApi/VVRestApiNodeJs/samples/sampleFormValidationScript.js +0 -126
  44. package/lib/VVRestApi/VVRestApiNodeJs/views/error.ejs +0 -8
  45. package/lib/VVRestApi/VVRestApiNodeJs/views/index.ejs +0 -8
@@ -0,0 +1,2552 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __esm = (fn, res) => function __init() {
8
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
9
+ };
10
+ var __export = (target, all) => {
11
+ for (var name in all)
12
+ __defProp(target, name, { get: all[name], enumerable: true });
13
+ };
14
+ var __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from))
17
+ if (!__hasOwnProp.call(to, key) && key !== except)
18
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
+ // If the importer is in node compatibility mode or this is not an ESM
24
+ // file that has been converted to a CommonJS file using a Babel-
25
+ // compatible transform (i.e. "__esModule" has not been set), then set
26
+ // "default" to the CommonJS "module.exports" for node compatibility.
27
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
28
+ mod
29
+ ));
30
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
31
+
32
+ // node_modules/tsup/assets/cjs_shims.js
33
+ var getImportMetaUrl, importMetaUrl;
34
+ var init_cjs_shims = __esm({
35
+ "node_modules/tsup/assets/cjs_shims.js"() {
36
+ getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
37
+ importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
38
+ }
39
+ });
40
+
41
+ // lib/http/sessionToken.js
42
+ var SessionToken;
43
+ var init_sessionToken = __esm({
44
+ "lib/http/sessionToken.js"() {
45
+ init_cjs_shims();
46
+ SessionToken = class _SessionToken {
47
+ constructor() {
48
+ this.isAuthenticated = false;
49
+ this.apiUrl = null;
50
+ this.baseUrl = null;
51
+ this.authenticationUrl = null;
52
+ this.customerAlias = null;
53
+ this.databaseAlias = null;
54
+ this.expirationDate = null;
55
+ this.accessToken = null;
56
+ this.tokenType = null;
57
+ this.refreshToken = null;
58
+ this.expiresIn = 0;
59
+ this.clientId = null;
60
+ this.clientSecret = null;
61
+ this.userId = null;
62
+ this.password = null;
63
+ this.audience = null;
64
+ }
65
+ createCopy() {
66
+ const newSession = new _SessionToken();
67
+ newSession.isAuthenticated = this.isAuthenticated;
68
+ newSession.apiUrl = this.apiUrl;
69
+ newSession.baseUrl = this.baseUrl;
70
+ newSession.authenticationUrl = this.authenticationUrl;
71
+ newSession.customerAlias = this.customerAlias;
72
+ newSession.databaseAlias = this.databaseAlias;
73
+ newSession.expirationDate = this.expirationDate;
74
+ newSession.accessToken = this.accessToken;
75
+ newSession.tokenType = this.tokenType;
76
+ newSession.refreshToken = this.refreshToken;
77
+ newSession.expiresIn = this.expiresIn;
78
+ newSession.clientId = this.clientId;
79
+ newSession.clientSecret = this.clientSecret;
80
+ newSession.userId = this.userId;
81
+ newSession.password = this.password;
82
+ newSession.audience = this.audience;
83
+ return newSession;
84
+ }
85
+ convertToJwt(jwt) {
86
+ this.tokenType = "jwt";
87
+ this.accessToken = jwt["token"];
88
+ this.expirationDate = new Date(jwt["expires"]);
89
+ this.expiresIn = 0;
90
+ }
91
+ };
92
+ }
93
+ });
94
+
95
+ // lib/http/authorize.js
96
+ var authorize_exports = {};
97
+ __export(authorize_exports, {
98
+ Authorize: () => Authorize,
99
+ default: () => authorize_default
100
+ });
101
+ var import_debug, import_js_yaml, import_fs, debug, Authorize, authorize_default;
102
+ var init_authorize = __esm({
103
+ "lib/http/authorize.js"() {
104
+ init_cjs_shims();
105
+ init_sessionToken();
106
+ import_debug = __toESM(require("debug"), 1);
107
+ import_js_yaml = __toESM(require("js-yaml"), 1);
108
+ import_fs = __toESM(require("fs"), 1);
109
+ debug = (0, import_debug.default)("visualvault:auth");
110
+ Authorize = class {
111
+ constructor() {
112
+ this.jsyaml = import_js_yaml.default;
113
+ this.fs = import_fs.default;
114
+ }
115
+ async acquireSecurityToken(clientId, clientSecret, userId, password, audience, baseUrl, apiUrl, customerAlias, databaseAlias, authenticationUrl) {
116
+ debug("acquireSecurityToken called for user: %s", userId);
117
+ try {
118
+ const sessionToken = await this.__getToken(
119
+ clientId,
120
+ clientSecret,
121
+ userId,
122
+ password,
123
+ audience,
124
+ baseUrl,
125
+ customerAlias,
126
+ databaseAlias,
127
+ authenticationUrl,
128
+ true
129
+ );
130
+ debug("acquireSecurityToken success");
131
+ if (typeof sessionToken != "undefined" && sessionToken != null) {
132
+ sessionToken.baseUrl = baseUrl;
133
+ sessionToken.apiUrl = apiUrl;
134
+ sessionToken.authenticationUrl = authenticationUrl;
135
+ sessionToken.customerAlias = customerAlias;
136
+ sessionToken.databaseAlias = databaseAlias;
137
+ sessionToken.clientId = clientId;
138
+ sessionToken.clientSecret = clientSecret;
139
+ sessionToken.userId = userId;
140
+ sessionToken.password = password;
141
+ sessionToken.audience = audience;
142
+ sessionToken.isAuthenticated = true;
143
+ }
144
+ return sessionToken;
145
+ } catch (error) {
146
+ debug("acquireSecurityToken failed: %s", error.message);
147
+ throw error;
148
+ }
149
+ }
150
+ async acquireJwt(jwt, baseUrl, apiUrl, authenticationUrl, customerAlias, databaseAlias) {
151
+ debug("acquireJwt called");
152
+ try {
153
+ const sessionToken = await this.__getJwt(
154
+ jwt,
155
+ baseUrl,
156
+ customerAlias,
157
+ databaseAlias,
158
+ authenticationUrl,
159
+ true
160
+ );
161
+ debug("acquireJwt success");
162
+ if (typeof sessionToken != "undefined" && sessionToken != null) {
163
+ sessionToken.baseUrl = baseUrl;
164
+ sessionToken.apiUrl = apiUrl;
165
+ sessionToken.authenticationUrl = authenticationUrl;
166
+ sessionToken.customerAlias = customerAlias;
167
+ sessionToken.databaseAlias = databaseAlias;
168
+ sessionToken.isAuthenticated = true;
169
+ sessionToken.isJwt = true;
170
+ }
171
+ return sessionToken;
172
+ } catch (error) {
173
+ debug("acquireJwt failed: %s", error.message);
174
+ throw error;
175
+ }
176
+ }
177
+ async reacquireSecurityToken(sessionToken) {
178
+ debug("reacquireSecurityToken called (isJwt: %s)", sessionToken.isJwt);
179
+ try {
180
+ if (sessionToken.isJwt) {
181
+ const newToken = await this.__getJwt(
182
+ sessionToken.accessToken,
183
+ sessionToken.baseUrl,
184
+ sessionToken.customerAlias,
185
+ sessionToken.databaseAlias,
186
+ sessionToken.authenticationUrl,
187
+ true
188
+ );
189
+ debug("reacquireSecurityToken success (JWT)");
190
+ return newToken;
191
+ } else {
192
+ const newToken = await this.__getToken(
193
+ sessionToken.clientId,
194
+ sessionToken.clientSecret,
195
+ sessionToken.userId,
196
+ sessionToken.password,
197
+ sessionToken.audience,
198
+ sessionToken.baseUrl,
199
+ sessionToken.customerAlias,
200
+ sessionToken.databaseAlias,
201
+ sessionToken.authenticationUrl,
202
+ true
203
+ );
204
+ debug("reacquireSecurityToken success (password grant)");
205
+ return newToken;
206
+ }
207
+ } catch (error) {
208
+ debug("reacquireSecurityToken failed: %s", error.message);
209
+ throw error;
210
+ }
211
+ }
212
+ async acquireRefreshToken(sessionToken) {
213
+ if (sessionToken.isJwt) {
214
+ return await this.reacquireSecurityToken(sessionToken);
215
+ }
216
+ const claim = {
217
+ grant_type: "refresh_token",
218
+ refresh_token: sessionToken.refreshToken,
219
+ client_id: sessionToken.clientId,
220
+ client_secret: sessionToken.clientSecret
221
+ };
222
+ if (sessionToken["audience"]) {
223
+ claim["audience"] = sessionToken["audience"];
224
+ }
225
+ const urlSecurity = sessionToken.baseUrl + sessionToken.authenticationUrl;
226
+ debug("acquireRefreshToken - URL: %s", urlSecurity);
227
+ try {
228
+ const response = await fetch(urlSecurity, {
229
+ method: "POST",
230
+ headers: {
231
+ "Content-Type": "application/x-www-form-urlencoded"
232
+ },
233
+ body: new URLSearchParams(claim)
234
+ });
235
+ const body = await response.text();
236
+ if (response.status === 200) {
237
+ debug("acquireRefreshToken success");
238
+ const responseObject = JSON.parse(body);
239
+ sessionToken.accessToken = responseObject.access_token;
240
+ sessionToken.expiresIn = responseObject.expires_in;
241
+ sessionToken.refreshToken = responseObject.refresh_token;
242
+ sessionToken.tokenType = responseObject.token_type;
243
+ const expireDate = /* @__PURE__ */ new Date();
244
+ expireDate.setSeconds(expireDate.getSeconds() + sessionToken.expiresIn);
245
+ sessionToken.expirationDate = expireDate;
246
+ sessionToken.isAuthenticated = true;
247
+ return sessionToken;
248
+ } else if (response.status === 401 || response.status === 403 || response.status === 400) {
249
+ sessionToken.isAuthenticated = false;
250
+ throw new Error(`Authorization has been refused for current credentials (HTTP ${response.status}): ${body.substring(0, 200)}`);
251
+ } else {
252
+ sessionToken.isAuthenticated = false;
253
+ throw new Error(`Unknown response for access token: HTTP ${response.status}`);
254
+ }
255
+ } catch (error) {
256
+ sessionToken.isAuthenticated = false;
257
+ debug("acquireRefreshToken error: %s", error.message);
258
+ throw error;
259
+ }
260
+ }
261
+ async __getToken(clientId, clientSecret, userId, password, audience, baseUrl, customerAlias, databaseAlias, authenticationUrl) {
262
+ const sessionToken = new SessionToken();
263
+ const claim = {
264
+ grant_type: "password",
265
+ client_id: clientId,
266
+ client_secret: clientSecret,
267
+ username: userId,
268
+ password,
269
+ scope: "vault"
270
+ };
271
+ const urlSecurity = baseUrl + authenticationUrl;
272
+ debug("__getToken - URL: %s, user: %s, customer: %s/%s, audience: %s", urlSecurity, userId, customerAlias, databaseAlias, audience);
273
+ try {
274
+ const response = await fetch(urlSecurity, {
275
+ method: "POST",
276
+ headers: {
277
+ "Content-Type": "application/x-www-form-urlencoded"
278
+ },
279
+ body: new URLSearchParams(claim)
280
+ });
281
+ const body = await response.text();
282
+ if (response.status === 200) {
283
+ const responseObject = JSON.parse(body);
284
+ sessionToken.accessToken = responseObject.access_token;
285
+ sessionToken.expiresIn = responseObject.expires_in;
286
+ sessionToken.refreshToken = responseObject.refresh_token;
287
+ sessionToken.tokenType = responseObject.token_type;
288
+ const expireDate = /* @__PURE__ */ new Date();
289
+ expireDate.setSeconds(expireDate.getSeconds() + sessionToken.expiresIn);
290
+ sessionToken.expirationDate = expireDate;
291
+ sessionToken.isAuthenticated = true;
292
+ debug("__getToken success");
293
+ return sessionToken;
294
+ } else if (response.status === 401 || response.status === 403 || response.status === 400) {
295
+ sessionToken.isAuthenticated = false;
296
+ throw new Error(`Authorization has been refused for current credentials (HTTP ${response.status}): ${body.substring(0, 200)}`);
297
+ } else {
298
+ sessionToken.isAuthenticated = false;
299
+ throw new Error(`Unknown response for access token: HTTP ${response.status}`);
300
+ }
301
+ } catch (error) {
302
+ sessionToken.isAuthenticated = false;
303
+ debug("__getToken error: %s", error.message);
304
+ throw error;
305
+ }
306
+ }
307
+ async __getJwt(jwt, baseUrl, customerAlias, databaseAlias, authenticationUrl) {
308
+ const sessionToken = new SessionToken();
309
+ const headers = {
310
+ Authorization: "Bearer " + jwt
311
+ };
312
+ const urlSecurity = baseUrl + authenticationUrl;
313
+ debug("__getJwt - URL: %s, customer: %s/%s", urlSecurity, customerAlias, databaseAlias);
314
+ try {
315
+ const response = await fetch(urlSecurity, {
316
+ method: "GET",
317
+ headers
318
+ });
319
+ const body = await response.text();
320
+ if (response.status === 200) {
321
+ const responseObject = JSON.parse(body);
322
+ sessionToken.accessToken = responseObject.data.token;
323
+ sessionToken.expirationDate = new Date(responseObject.data.expires);
324
+ sessionToken.isAuthenticated = true;
325
+ sessionToken.isJwt = true;
326
+ debug("__getJwt success");
327
+ return sessionToken;
328
+ } else if (response.status === 401 || response.status === 403 || response.status === 400) {
329
+ sessionToken.isAuthenticated = false;
330
+ throw new Error(`Authorization has been refused for current credentials (HTTP ${response.status}): ${body.substring(0, 200)}`);
331
+ } else {
332
+ sessionToken.isAuthenticated = false;
333
+ throw new Error(`Unknown response for JWT: HTTP ${response.status}`);
334
+ }
335
+ } catch (error) {
336
+ sessionToken.isAuthenticated = false;
337
+ debug("__getJwt error: %s", error.message);
338
+ throw error;
339
+ }
340
+ }
341
+ endsWith(source, suffix) {
342
+ return source.indexOf(suffix, source.length - suffix.length) !== -1;
343
+ }
344
+ };
345
+ authorize_default = Authorize;
346
+ }
347
+ });
348
+
349
+ // lib/VVRestApi.js
350
+ var VVRestApi_exports = {};
351
+ __export(VVRestApi_exports, {
352
+ Authorize: () => Authorize2,
353
+ VVClient: () => VVClient,
354
+ default: () => VVRestApi_default,
355
+ forms: () => forms
356
+ });
357
+ module.exports = __toCommonJS(VVRestApi_exports);
358
+ init_cjs_shims();
359
+
360
+ // lib/DocApi.js
361
+ init_cjs_shims();
362
+
363
+ // lib/common.js
364
+ init_cjs_shims();
365
+
366
+ // lib/http/httpHelper.js
367
+ init_cjs_shims();
368
+ var import_debug2 = __toESM(require("debug"), 1);
369
+ var debug2 = (0, import_debug2.default)("visualvault:http");
370
+ var HttpHelper = class {
371
+ constructor(sessionToken, yamlConfig) {
372
+ this._sessionToken = sessionToken;
373
+ this._config = yamlConfig;
374
+ this._maxRetries = 3;
375
+ }
376
+ async doVvClientRequest(url, options, params, data, buffer) {
377
+ if (this._sessionToken.expirationDate < new Date((/* @__PURE__ */ new Date()).getTime() + 30 * 1e3)) {
378
+ debug2("accessToken has expired, calling __acquireRefreshToken");
379
+ try {
380
+ await this.__acquireRefreshToken();
381
+ debug2("return success from __acquireRefreshToken");
382
+ return await this.__doVvClientCallRequest(url, options, params, data, buffer);
383
+ } catch (error) {
384
+ debug2("return fail from __acquireRefreshToken: %s", error.message);
385
+ throw new Error("Unable to obtain Authorization, error: " + error);
386
+ }
387
+ } else {
388
+ return await this.__doVvClientCallRequest(url, options, params, data, buffer);
389
+ }
390
+ }
391
+ async __doVvClientCallRequest(url, options, params, data, buffer, retries = 0) {
392
+ try {
393
+ let responseData;
394
+ if (options.method === "GET") {
395
+ responseData = await this.httpGet(url, params);
396
+ } else if (options.method === "GETSTREAM") {
397
+ responseData = await this.httpGetStream(url, params);
398
+ } else if (options.method === "POST") {
399
+ responseData = await this.httpPost(url, params, data);
400
+ } else if (options.method === "POSTSTREAM") {
401
+ responseData = await this.httpPostStream(url, params, data, buffer);
402
+ } else if (options.method === "PUT") {
403
+ responseData = await this.httpPut(url, params, data);
404
+ } else if (options.method === "PUTSTREAM") {
405
+ responseData = await this.httpPutStream(url, params, data, buffer);
406
+ } else if (options.method === "DELETE") {
407
+ responseData = await this.httpDelete(url, params);
408
+ } else {
409
+ throw new Error("http request method name error");
410
+ }
411
+ return responseData;
412
+ } catch (error) {
413
+ if (error.status === 429 && retries < this._maxRetries) {
414
+ const timeout = this.__getRetryDelay(error.retryTime);
415
+ debug2("Timed Out: Retrying in %d ms. (%d retries left)", timeout, this._maxRetries - retries - 1);
416
+ await new Promise((resolve) => setTimeout(resolve, timeout));
417
+ return await this.__doVvClientCallRequest(url, options, params, data, buffer, retries + 1);
418
+ }
419
+ throw error;
420
+ }
421
+ }
422
+ async __makeRequest(url, options) {
423
+ const headers = {
424
+ "Authorization": "Bearer " + this._sessionToken.accessToken,
425
+ "Content-Type": "application/json"
426
+ };
427
+ debug2("Performing request to url: %s", url);
428
+ const fetchOptions = {
429
+ method: options.method,
430
+ headers: { ...headers, ...options.headers }
431
+ };
432
+ if (options.qs && Object.keys(options.qs).length > 0) {
433
+ const queryString = new URLSearchParams(options.qs).toString();
434
+ url = `${url}?${queryString}`;
435
+ }
436
+ if (options.json && (options.method === "POST" || options.method === "PUT")) {
437
+ fetchOptions.body = JSON.stringify(options.json);
438
+ }
439
+ const response = await fetch(url, fetchOptions);
440
+ const responseText = await response.text();
441
+ if (!response.ok) {
442
+ let parsedData;
443
+ try {
444
+ parsedData = JSON.parse(responseText);
445
+ } catch (e) {
446
+ parsedData = { meta: responseText };
447
+ }
448
+ if (response.status === 401 || response.status === 403) {
449
+ this._sessionToken.isAuthenticated = false;
450
+ throw new Error(JSON.stringify(parsedData.meta));
451
+ } else if (response.status === 429) {
452
+ const error = new Error(JSON.stringify(parsedData.meta));
453
+ error.status = 429;
454
+ error.retryTime = parsedData.meta?.retryTime;
455
+ throw error;
456
+ } else {
457
+ throw new Error(responseText);
458
+ }
459
+ }
460
+ return responseText;
461
+ }
462
+ async __makePostStreamRequest(url, options, buffer) {
463
+ debug2("Performing stream request to url: %s", url);
464
+ const formData = new FormData();
465
+ if (options.json) {
466
+ for (const key in options.json) {
467
+ if (options.json.hasOwnProperty(key)) {
468
+ formData.append(key, options.json[key]);
469
+ }
470
+ }
471
+ }
472
+ if (Buffer.isBuffer(buffer)) {
473
+ const filename = options.json?.fileName || "file";
474
+ const blob = new Blob([buffer]);
475
+ formData.append("fileUpload", blob, filename);
476
+ } else if (Array.isArray(buffer)) {
477
+ for (let i = 0; i < buffer.length; i++) {
478
+ const fileInfoObj = buffer[i];
479
+ if (Buffer.isBuffer(fileInfoObj.buffer)) {
480
+ const fileName = fileInfoObj.fileName || `file${i}`;
481
+ const blob = new Blob([fileInfoObj.buffer]);
482
+ formData.append("fileUpload", blob, fileName);
483
+ } else {
484
+ throw new Error(`Invalid 'buffer' property found on fileObj at index ${i}`);
485
+ }
486
+ }
487
+ } else {
488
+ throw new Error("Expecting Buffer");
489
+ }
490
+ const headers = {
491
+ "Authorization": "Bearer " + this._sessionToken.accessToken
492
+ };
493
+ const response = await fetch(url, {
494
+ method: options.method,
495
+ headers,
496
+ body: formData
497
+ });
498
+ const responseText = await response.text();
499
+ if (!response.ok) {
500
+ throw new Error(responseText);
501
+ }
502
+ return responseText;
503
+ }
504
+ async httpGet(url, params) {
505
+ const options = { method: "GET", qs: params || {}, headers: {}, json: null };
506
+ if (this._sessionToken.accessToken == null) {
507
+ throw new Error("Access token is null");
508
+ }
509
+ return await this.__makeRequest(url, options);
510
+ }
511
+ async httpGetStream(url, params) {
512
+ if (this._sessionToken.accessToken == null) {
513
+ throw new Error("Access token is null");
514
+ }
515
+ const headers = {
516
+ "Authorization": "Bearer " + this._sessionToken.accessToken,
517
+ "Content-Type": "application/json; charset=utf-8"
518
+ };
519
+ if (params && Object.keys(params).length > 0) {
520
+ const queryString = new URLSearchParams(params).toString();
521
+ url = `${url}?${queryString}`;
522
+ }
523
+ const response = await fetch(url, { method: "GET", headers });
524
+ if (!response.ok) {
525
+ throw new Error(`HTTP error! status: ${response.status}`);
526
+ }
527
+ const buffer = await response.arrayBuffer();
528
+ return Buffer.from(buffer);
529
+ }
530
+ async httpPost(url, params, data) {
531
+ const options = { method: "POST", qs: params || {}, json: data, headers: {} };
532
+ if (this._sessionToken.accessToken == null) {
533
+ throw new Error("Access token is null");
534
+ }
535
+ return await this.__makeRequest(url, options);
536
+ }
537
+ async httpPostStream(url, params, data, buffer) {
538
+ const options = { method: "POST", qs: params || {}, json: data, headers: {} };
539
+ if (this._sessionToken.accessToken == null) {
540
+ throw new Error("Access token is null");
541
+ }
542
+ return await this.__makePostStreamRequest(url, options, buffer);
543
+ }
544
+ async httpPut(url, params, data) {
545
+ const options = { method: "PUT", qs: params || {}, json: data, headers: {} };
546
+ if (this._sessionToken.accessToken == null) {
547
+ throw new Error("Access token is null");
548
+ }
549
+ return await this.__makeRequest(url, options);
550
+ }
551
+ async httpPutStream(url, params, data, buffer) {
552
+ const options = { method: "PUT", qs: params || {}, json: data, headers: {} };
553
+ if (this._sessionToken.accessToken == null) {
554
+ throw new Error("Access token is null");
555
+ }
556
+ return await this.__makePostStreamRequest(url, options, buffer);
557
+ }
558
+ async httpDelete(url, params) {
559
+ const options = { method: "DELETE", qs: params || {}, json: null, headers: {} };
560
+ if (this._sessionToken.accessToken == null) {
561
+ throw new Error("Access token is null");
562
+ }
563
+ return await this.__makeRequest(url, options);
564
+ }
565
+ async __acquireRefreshToken() {
566
+ this._sessionToken.isAuthenticated = false;
567
+ const { Authorize: Authorize3 } = await Promise.resolve().then(() => (init_authorize(), authorize_exports));
568
+ const vvAuthorize = new Authorize3();
569
+ try {
570
+ await vvAuthorize.acquireRefreshToken(this._sessionToken);
571
+ } catch (error) {
572
+ await vvAuthorize.reacquireSecurityToken(this._sessionToken);
573
+ }
574
+ }
575
+ request(httpVerb, url, params, data) {
576
+ const options = { method: httpVerb.toUpperCase() };
577
+ debug2("Performing %s request to url: %s", httpVerb.toUpperCase(), url);
578
+ return this.doVvClientRequest(url, options, params, data);
579
+ }
580
+ getUrl(resourceUrl) {
581
+ return this._sessionToken.baseUrl + this._sessionToken.apiUrl + resourceUrl;
582
+ }
583
+ __getRetryDelay(retryTime) {
584
+ let delay = 10;
585
+ if (retryTime && !isNaN(Date.parse(retryTime))) {
586
+ const now = /* @__PURE__ */ new Date();
587
+ delay = Date.parse(retryTime) - now.getTime();
588
+ if (delay < 0) {
589
+ delay *= -1;
590
+ }
591
+ }
592
+ return delay;
593
+ }
594
+ };
595
+
596
+ // lib/common.js
597
+ init_sessionToken();
598
+ init_authorize();
599
+ init_sessionToken();
600
+ init_authorize();
601
+ var common_default = {
602
+ httpHelper: HttpHelper,
603
+ sessionToken: SessionToken,
604
+ authorize: Authorize
605
+ };
606
+
607
+ // lib/docApi/documentManager.js
608
+ init_cjs_shims();
609
+ var DocumentManager = class {
610
+ constructor(httpHelper) {
611
+ this._httpHelper = httpHelper;
612
+ }
613
+ async GetRevision(documentRevisionId) {
614
+ let resourceUri = this._httpHelper._config.ResourceUri.DocApi.GetRevision;
615
+ resourceUri = resourceUri.replace("{id}", documentRevisionId);
616
+ const url = this._httpHelper.getUrl(resourceUri);
617
+ const opts = { method: "GET" };
618
+ return this._httpHelper.doVvClientRequest(url, opts, null, null);
619
+ }
620
+ async getDocumentOcrStatus(documentRevisionId) {
621
+ let resourceUri = this._httpHelper._config.ResourceUri.DocApi.OcrStatus;
622
+ resourceUri = resourceUri.replace("{id}", documentRevisionId);
623
+ const url = this._httpHelper.getUrl(resourceUri);
624
+ const opts = { method: "GET" };
625
+ return this._httpHelper.doVvClientRequest(url, opts, null, null);
626
+ }
627
+ async updateDocumentOcrStatus(documentRevisionId, data) {
628
+ let resourceUri = this._httpHelper._config.ResourceUri.DocApi.OcrStatus;
629
+ resourceUri = resourceUri.replace("{id}", documentRevisionId);
630
+ const url = this._httpHelper.getUrl(resourceUri);
631
+ const opts = { method: "PUT" };
632
+ return this._httpHelper.doVvClientRequest(url, opts, null, data);
633
+ }
634
+ async search(criteriaList, searchFolders, excludeFolders, sortBy, sortDirection = "desc", page = 0, take = 15, archiveType = 0, roleSecurity = false) {
635
+ const url = this._httpHelper.getUrl(this._httpHelper._config.ResourceUri.DocApi.AdvancedSearch);
636
+ const data = {
637
+ criteriaList,
638
+ searchFolders,
639
+ excludeFolders,
640
+ sortBy,
641
+ sortDirection,
642
+ page,
643
+ take,
644
+ archiveType,
645
+ roleSecurity
646
+ };
647
+ const options = { method: "POST" };
648
+ return this._httpHelper.doVvClientRequest(url, options, null, data);
649
+ }
650
+ };
651
+
652
+ // lib/DocApi.js
653
+ var import_js_yaml2 = __toESM(require("js-yaml"), 1);
654
+ var import_fs2 = __toESM(require("fs"), 1);
655
+ var import_url = require("url");
656
+ var import_path = __toESM(require("path"), 1);
657
+ var __filename2 = (0, import_url.fileURLToPath)(importMetaUrl);
658
+ var __dirname = import_path.default.dirname(__filename2);
659
+ var DocApi = class {
660
+ constructor(sessionToken, docApiConfig) {
661
+ if (!sessionToken["tokenType"] && sessionToken["tokenType"] != "jwt") {
662
+ return;
663
+ }
664
+ const yamlConfig = import_js_yaml2.default.load(import_fs2.default.readFileSync(__dirname + "/config.yml", "utf8"));
665
+ this._httpHelper = new common_default.httpHelper(sessionToken, yamlConfig);
666
+ this.isEnabled = docApiConfig["isEnabled"] || false;
667
+ this.baseUrl = docApiConfig["apiUrl"] || null;
668
+ this.roleSecurity = docApiConfig["roleSecurity"] || false;
669
+ if (this.isEnabled) {
670
+ this.documents = new DocumentManager(this._httpHelper);
671
+ }
672
+ }
673
+ };
674
+ var DocApi_default = DocApi;
675
+
676
+ // lib/FormsApi.js
677
+ init_cjs_shims();
678
+
679
+ // lib/formsApi/formInstanceManager.js
680
+ init_cjs_shims();
681
+ var FormInstanceManager = class {
682
+ constructor(httpHelper) {
683
+ this._httpHelper = httpHelper;
684
+ }
685
+ async postForm(params, data, formTemplateRevisionId) {
686
+ const resourceUri = this._httpHelper._config.ResourceUri.FormsApi.FormInstance;
687
+ const url = this._httpHelper.getUrl(resourceUri);
688
+ const opts = { method: "POST" };
689
+ data["formTemplateId"] = formTemplateRevisionId || data["formTemplateId"];
690
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
691
+ }
692
+ async postFormRevision(params, data, formTemplateRevisionId, formId) {
693
+ const resourceUri = this._httpHelper._config.ResourceUri.FormsApi.FormInstance;
694
+ const url = this._httpHelper.getUrl(resourceUri);
695
+ const opts = { method: "PUT" };
696
+ data["formTemplateId"] = formTemplateRevisionId || data["formTemplateId"];
697
+ data["formId"] = formId || data["formId"];
698
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
699
+ }
700
+ };
701
+ var formInstanceManager_default = FormInstanceManager;
702
+
703
+ // lib/FormsApi.js
704
+ var import_js_yaml3 = __toESM(require("js-yaml"), 1);
705
+ var import_fs3 = __toESM(require("fs"), 1);
706
+ var import_url2 = require("url");
707
+ var import_path2 = __toESM(require("path"), 1);
708
+ var __filename3 = (0, import_url2.fileURLToPath)(importMetaUrl);
709
+ var __dirname2 = import_path2.default.dirname(__filename3);
710
+ var FormsApi = class {
711
+ constructor(sessionToken, formsApiConfig) {
712
+ if (!sessionToken["tokenType"] && sessionToken["tokenType"] != "jwt") {
713
+ return;
714
+ }
715
+ const yamlConfig = import_js_yaml3.default.load(import_fs3.default.readFileSync(__dirname2 + "/config.yml", "utf8"));
716
+ this._httpHelper = new common_default.httpHelper(sessionToken, yamlConfig);
717
+ this.isEnabled = formsApiConfig["isEnabled"] || false;
718
+ this.baseUrl = formsApiConfig["formsApiUrl"] || null;
719
+ if (this.isEnabled) {
720
+ this.formInstances = new formInstanceManager_default(this._httpHelper);
721
+ }
722
+ }
723
+ };
724
+ var FormsApi_default = FormsApi;
725
+
726
+ // lib/ObjectsApi.js
727
+ init_cjs_shims();
728
+
729
+ // lib/objectsApi/modelManager.js
730
+ init_cjs_shims();
731
+ var ModelManager = class {
732
+ constructor(httpHelper) {
733
+ this._httpHelper = httpHelper;
734
+ }
735
+ /**
736
+ * Retrieves a list of available models
737
+ * @param {object} params - Optional URL parameters to include in the request
738
+ */
739
+ async getModels(params) {
740
+ const resourceUri = this._httpHelper._config.ResourceUri.ObjectsApi.Models;
741
+ const url = this._httpHelper.getUrl(resourceUri);
742
+ const opts = { method: "GET" };
743
+ params = params || {};
744
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
745
+ }
746
+ /**
747
+ * Retrieves a specific model by its ID
748
+ * @param {string} modelId - The ID (Guid) for the requested model
749
+ * @param {object} params - Optional URL parameters to include in the request
750
+ */
751
+ async getModelById(modelId, params) {
752
+ let resourceUri = this._httpHelper._config.ResourceUri.ObjectsApi.ModelById;
753
+ resourceUri = resourceUri.replace("{id}", modelId);
754
+ const url = this._httpHelper.getUrl(resourceUri);
755
+ const opts = { method: "GET" };
756
+ params = params || {};
757
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
758
+ }
759
+ };
760
+ var modelManager_default = ModelManager;
761
+
762
+ // lib/objectsApi/objectManager.js
763
+ init_cjs_shims();
764
+ var ObjectManager = class {
765
+ constructor(httpHelper) {
766
+ this._httpHelper = httpHelper;
767
+ }
768
+ /**
769
+ * Retrieves a specific object by its ID
770
+ * @param {string} objectId - The ID (Guid) for the requested object
771
+ * @param {object} params - Optional URL parameters to include in the request
772
+ */
773
+ async getObject(objectId, params) {
774
+ let resourceUri = this._httpHelper._config.ResourceUri.ObjectsApi.ObjectById;
775
+ resourceUri = resourceUri.replace("{id}", objectId);
776
+ const url = this._httpHelper.getUrl(resourceUri);
777
+ const opts = { method: "GET" };
778
+ params = params || {};
779
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
780
+ }
781
+ /**
782
+ * Retrieves a paged list of objects associated with a given model
783
+ * @param {string} modelId - The ID (Guid) for the requested model to search
784
+ * @param {object} data - Data to send in the request body
785
+ * @param {object} params - Optional URL parameters to include in the request
786
+ */
787
+ async getObjectsByModelId(modelId, data, params) {
788
+ let resourceUri = this._httpHelper._config.ResourceUri.ObjectsApi.ObjectSearchByModelId;
789
+ resourceUri = resourceUri.replace("{modelId}", modelId);
790
+ const url = this._httpHelper.getUrl(resourceUri);
791
+ const opts = { method: "POST" };
792
+ data = data || {};
793
+ params = params || {};
794
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
795
+ }
796
+ /**
797
+ * Creates a new object adhering to a given model
798
+ * @param {string} modelId - The ID (Guid) used to create a new object for that model
799
+ * @param {object} data - Data to send in the request body
800
+ * @param {object} params - Optional URL parameters to include in the request
801
+ */
802
+ async createObject(modelId, data, params) {
803
+ const resourceUri = this._httpHelper._config.ResourceUri.ObjectsApi.Object;
804
+ const url = this._httpHelper.getUrl(resourceUri);
805
+ const opts = { method: "POST" };
806
+ data = data || {};
807
+ params = params || {};
808
+ data["modelId"] = modelId || data["modelId"];
809
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
810
+ }
811
+ /**
812
+ * Updates an existing object by its ID (Guid) and revision ID (Guid)
813
+ * @param {string} objectId - The ID (Guid) for the requested object to update
814
+ * @param {string} objectRevisionId - The revision ID (Guid) for the requested object to update
815
+ * @param {object} data - Data to send in the request body
816
+ * @param {object} params - Optional URL parameters to include in the request
817
+ */
818
+ async updateObject(objectId, objectRevisionId, data, params) {
819
+ let resourceUri = this._httpHelper._config.ResourceUri.ObjectsApi.ObjectById;
820
+ resourceUri = resourceUri.replace("{id}", objectId);
821
+ const url = this._httpHelper.getUrl(resourceUri);
822
+ const opts = { method: "PUT" };
823
+ data = data || {};
824
+ params = params || {};
825
+ data["revisionId"] = objectRevisionId || data["revisionId"];
826
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
827
+ }
828
+ /**
829
+ * Deletes an existing object by its ID (Guid)
830
+ * @param {string} objectId - The ID (Guid) for the requested object to delete
831
+ * @param {object} params - Optional URL parameters to include in the request
832
+ */
833
+ async deleteObject(objectId, params) {
834
+ let resourceUri = this._httpHelper._config.ResourceUri.ObjectsApi.ObjectById;
835
+ resourceUri = resourceUri.replace("{id}", objectId);
836
+ const url = this._httpHelper.getUrl(resourceUri);
837
+ const opts = { method: "DELETE" };
838
+ params = params || {};
839
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
840
+ }
841
+ };
842
+ var objectManager_default = ObjectManager;
843
+
844
+ // lib/ObjectsApi.js
845
+ var import_js_yaml4 = __toESM(require("js-yaml"), 1);
846
+ var import_fs4 = __toESM(require("fs"), 1);
847
+ var import_url3 = require("url");
848
+ var import_path3 = __toESM(require("path"), 1);
849
+ var __filename4 = (0, import_url3.fileURLToPath)(importMetaUrl);
850
+ var __dirname3 = import_path3.default.dirname(__filename4);
851
+ var ObjectsApi = class {
852
+ constructor(sessionToken, objectsApiConfig) {
853
+ if (!sessionToken["tokenType"] && sessionToken["tokenType"] != "jwt") {
854
+ return;
855
+ }
856
+ const yamlConfig = import_js_yaml4.default.load(import_fs4.default.readFileSync(__dirname3 + "/config.yml", "utf8"));
857
+ this._httpHelper = new common_default.httpHelper(sessionToken, yamlConfig);
858
+ this.isEnabled = objectsApiConfig["isEnabled"] || false;
859
+ this.baseUrl = objectsApiConfig["apiUrl"] || null;
860
+ if (this.isEnabled) {
861
+ this.models = new modelManager_default(this._httpHelper);
862
+ this.objects = new objectManager_default(this._httpHelper);
863
+ }
864
+ }
865
+ };
866
+ var ObjectsApi_default = ObjectsApi;
867
+
868
+ // lib/StudioApi.js
869
+ init_cjs_shims();
870
+
871
+ // lib/studioApi/workflowManager.js
872
+ init_cjs_shims();
873
+ var WorkflowManager = class {
874
+ constructor(httpHelper) {
875
+ this._httpHelper = httpHelper;
876
+ }
877
+ async getWorkflow(workflowId) {
878
+ const resourceUri = this._httpHelper._config.ResourceUri.StudioApi.WorkflowLatestPublishedId.replace("{id}", workflowId);
879
+ const url = this._httpHelper.getUrl(resourceUri);
880
+ const opts = { method: "GET" };
881
+ const data = {};
882
+ const params = {};
883
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
884
+ }
885
+ async getWorkflowByName(workflowName) {
886
+ const resourceUri = this._httpHelper._config.ResourceUri.StudioApi.WorkflowLatestPublished;
887
+ const url = this._httpHelper.getUrl(resourceUri);
888
+ const opts = { method: "GET" };
889
+ const data = {};
890
+ const params = { name: workflowName };
891
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
892
+ }
893
+ async getWorkflowVariables(params, workflowId) {
894
+ const resourceUri = this._httpHelper._config.ResourceUri.StudioApi.WorkflowVariables.replace("{id}", workflowId);
895
+ const url = this._httpHelper.getUrl(resourceUri);
896
+ const opts = { method: "GET" };
897
+ const data = {};
898
+ params = params || {};
899
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
900
+ }
901
+ /**
902
+ * Triggers workflow
903
+ * @param {string} workflowId
904
+ * @param {number} workflowRevision
905
+ * @param {string} objectId
906
+ * @param {object[]} workflowVariables - workflow values to be submitted to the workflow
907
+ * * @param {string} workflowVariables[].name = name of variable
908
+ * * @param {*} workflowVariables[].value - value to be passed
909
+ * * @param {number} workflowVariables[].dataType - Text: 1, Number: 2, Date: 3, Boolean: 4
910
+ */
911
+ async triggerWorkflow(workflowId, workflowRevision, objectId, workflowVariables) {
912
+ const resourceUri = this._httpHelper._config.ResourceUri.StudioApi.WorkflowRun.replace("{id}", workflowId).replace("{revision}", workflowRevision);
913
+ const url = this._httpHelper.getUrl(resourceUri);
914
+ const opts = { method: "POST" };
915
+ const data = {
916
+ objectId,
917
+ reference: "API",
918
+ data: {
919
+ workflowVariables,
920
+ dataSetVariables: []
921
+ }
922
+ };
923
+ const params = {};
924
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
925
+ }
926
+ /**
927
+ * Terminates the workflow instance
928
+ * @param {string} workflowId
929
+ * @param {string} instanceId
930
+ * @returns
931
+ */
932
+ async terminateWorkflow(workflowId, instanceId) {
933
+ const resourceUri = this._httpHelper._config.ResourceUri.StudioApi.WorkflowTerminate.replace("{workflowId}", workflowId).replace("{instanceId}", instanceId);
934
+ const url = this._httpHelper.getUrl(resourceUri);
935
+ const opts = { method: "POST" };
936
+ const data = {};
937
+ const params = {};
938
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
939
+ }
940
+ /**
941
+ * Returns workflow history for an object under the provided workflow
942
+ * @param {string} workflowId
943
+ * @param {string} objectId
944
+ * @returns
945
+ */
946
+ async GetWorkflowHistoryForObject(objectId, workflowId) {
947
+ const resourceUri = this._httpHelper._config.ResourceUri.StudioApi.WorkflowHistoryObject.replace("{workflowId}", workflowId).replace("{objectId}", objectId);
948
+ const url = this._httpHelper.getUrl(resourceUri);
949
+ const opts = { method: "GET" };
950
+ const data = {};
951
+ const params = {};
952
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
953
+ }
954
+ /**
955
+ * Returns the running workflow, if any, for an object under the provided workflow
956
+ * @param {string} workflowId
957
+ * @param {string} objectId
958
+ * @returns
959
+ */
960
+ async GetRunningWorkflowForObject(objectId, workflowId) {
961
+ const resourceUri = this._httpHelper._config.ResourceUri.StudioApi.WorkflowHistoryRunningObject.replace("{workflowId}", workflowId).replace("{objectId}", objectId);
962
+ const url = this._httpHelper.getUrl(resourceUri);
963
+ const opts = { method: "GET" };
964
+ const data = {};
965
+ const params = {};
966
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
967
+ }
968
+ };
969
+ var workflowManager_default = WorkflowManager;
970
+
971
+ // lib/studioApi/rolesAndPermissionsManager.js
972
+ init_cjs_shims();
973
+ var RolesAndPermissionsManager = class {
974
+ constructor(httpHelper) {
975
+ this._httpHelper = httpHelper;
976
+ }
977
+ /**
978
+ * Retrieves available features for the requesting user
979
+ * @param {object} params - Optional URL parameters to include in the request
980
+ */
981
+ async getUserFeatures(params) {
982
+ var resourceUri = this._httpHelper._config.ResourceUri.StudioApi.ResourceUserFeatures;
983
+ var url = this._httpHelper.getUrl(resourceUri);
984
+ var opts = { method: "GET" };
985
+ var data = {};
986
+ params = params || {};
987
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
988
+ }
989
+ };
990
+ var rolesAndPermissionsManager_default = RolesAndPermissionsManager;
991
+
992
+ // lib/StudioApi.js
993
+ var import_js_yaml5 = __toESM(require("js-yaml"), 1);
994
+ var import_fs5 = __toESM(require("fs"), 1);
995
+ var import_url4 = require("url");
996
+ var import_path4 = __toESM(require("path"), 1);
997
+ var __filename5 = (0, import_url4.fileURLToPath)(importMetaUrl);
998
+ var __dirname4 = import_path4.default.dirname(__filename5);
999
+ var StudioApi = class {
1000
+ constructor(sessionToken, studioApiConfig) {
1001
+ if (!sessionToken["tokenType"] && sessionToken["tokenType"] != "jwt") {
1002
+ return;
1003
+ }
1004
+ const yamlConfig = import_js_yaml5.default.load(import_fs5.default.readFileSync(__dirname4 + "/config.yml", "utf8"));
1005
+ this._httpHelper = new common_default.httpHelper(sessionToken, yamlConfig);
1006
+ this.isEnabled = studioApiConfig["isEnabled"] || false;
1007
+ this.baseUrl = studioApiConfig["studioApiUrl"] || null;
1008
+ if (this.isEnabled) {
1009
+ this.workflow = new workflowManager_default(this._httpHelper);
1010
+ this.permissions = new rolesAndPermissionsManager_default(this._httpHelper);
1011
+ }
1012
+ }
1013
+ };
1014
+ var StudioApi_default = StudioApi;
1015
+
1016
+ // lib/NotificationsApi.js
1017
+ init_cjs_shims();
1018
+
1019
+ // lib/notificationsApi/userNotificationsManager.js
1020
+ init_cjs_shims();
1021
+ var UserNotificationsManager = class {
1022
+ constructor(httpHelper) {
1023
+ this._httpHelper = httpHelper;
1024
+ }
1025
+ async forceUIRefresh(userGuid) {
1026
+ const resourceUri = this._httpHelper._config.ResourceUri.NotificationsApi.ForceUIRefresh.replace("{id}", userGuid);
1027
+ const url = this._httpHelper.getUrl(resourceUri);
1028
+ const opts = { method: "POST" };
1029
+ const params = {};
1030
+ const data = {};
1031
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
1032
+ }
1033
+ };
1034
+ var userNotificationsManager_default = UserNotificationsManager;
1035
+
1036
+ // lib/NotificationsApi.js
1037
+ var import_js_yaml6 = __toESM(require("js-yaml"), 1);
1038
+ var import_fs6 = __toESM(require("fs"), 1);
1039
+ var import_url5 = require("url");
1040
+ var import_path5 = __toESM(require("path"), 1);
1041
+ var __filename6 = (0, import_url5.fileURLToPath)(importMetaUrl);
1042
+ var __dirname5 = import_path5.default.dirname(__filename6);
1043
+ var NotificationsApi = class {
1044
+ constructor(sessionToken, notificationsApiConfig) {
1045
+ if (!sessionToken["tokenType"] && sessionToken["tokenType"] != "jwt") {
1046
+ return;
1047
+ }
1048
+ const yamlConfig = import_js_yaml6.default.load(import_fs6.default.readFileSync(__dirname5 + "/config.yml", "utf8"));
1049
+ this._httpHelper = new common_default.httpHelper(sessionToken, yamlConfig);
1050
+ this.isEnabled = notificationsApiConfig["isEnabled"] || false;
1051
+ this.baseUrl = notificationsApiConfig["apiUrl"] || null;
1052
+ if (this.isEnabled) {
1053
+ this.users = new userNotificationsManager_default(this._httpHelper);
1054
+ }
1055
+ }
1056
+ };
1057
+ var NotificationsApi_default = NotificationsApi;
1058
+
1059
+ // lib/VVRestApi.js
1060
+ var import_js_yaml7 = __toESM(require("js-yaml"), 1);
1061
+ var import_fs7 = __toESM(require("fs"), 1);
1062
+ var import_url6 = require("url");
1063
+ var import_path6 = __toESM(require("path"), 1);
1064
+ var import_debug5 = __toESM(require("debug"), 1);
1065
+
1066
+ // lib/vvRestApi/constants.js
1067
+ init_cjs_shims();
1068
+ var Constants = class {
1069
+ constructor() {
1070
+ }
1071
+ alertEventIds = {
1072
+ // Folder Events
1073
+ folderSecurityModified: "F06FD123-2C52-4F43-9122-34335A5BD8C6",
1074
+ // "CategorySecurity"
1075
+ childFolderSecurityModified: "30167D46-86CF-4E89-B1AE-FC00BB378F67",
1076
+ // "CategorySecurityCascade"
1077
+ folderDocumentAdded: "3702CFBF-555C-4032-BFB2-E25829788BAC",
1078
+ // "NewCategoryDoc"
1079
+ childFolderDocumentAdded: "28946E3C-AEAF-402B-BCE3-8DEAC3D19877",
1080
+ // "NewCategoryDocCascade"
1081
+ // Document Events
1082
+ documentCheckedIn: "D47804AB-AEE9-4002-BAB5-9F1AC0366076",
1083
+ // "CheckIn"
1084
+ documentCheckedOut: "4BBA55C1-7AF6-48FF-BFBE-EC7A58EB7F01",
1085
+ // "CheckOut"
1086
+ documentDetailsModified: "3B9D493F-2B45-4877-ABC1-5CA74F92723D",
1087
+ // "DocumentDetails"
1088
+ documentSecurityModified: "BAC187DC-78A8-4A8B-B50F-DB5D5AEE11B9",
1089
+ // "DocumentSecurity"
1090
+ documentViewed: "140B9E97-8D93-48D0-837B-AB4FD419B6D6",
1091
+ // "DocumentViewed"
1092
+ // Project Events
1093
+ projectDocumentAddedOrRemoved: "300DB724-5C51-4C38-B2E2-FFE19634A373",
1094
+ // "NewProjectDoc"
1095
+ projectViewed: "92F0C5F4-68DC-4309-9ABF-13B8E2198F79"
1096
+ // "ProjectView"
1097
+ };
1098
+ securityRoles = {
1099
+ // RoleType
1100
+ Owner: "Owner",
1101
+ Editor: "Editor",
1102
+ Viewer: "Viewer"
1103
+ };
1104
+ securityMemberType = {
1105
+ // MemberType
1106
+ User: "User",
1107
+ Group: "Group"
1108
+ };
1109
+ relationType = {
1110
+ Parent: "Parent",
1111
+ Child: "Child",
1112
+ Peer: "Peer"
1113
+ };
1114
+ };
1115
+
1116
+ // lib/vvRestApi/configurationManager.js
1117
+ init_cjs_shims();
1118
+ var ConfigurationManager = class {
1119
+ constructor(httpHelper) {
1120
+ this._httpHelper = httpHelper;
1121
+ }
1122
+ getDocApiConfig() {
1123
+ const url = this._httpHelper.getUrl(this._httpHelper._config.ResourceUri.ConfigurationDocApi);
1124
+ const opts = { method: "GET" };
1125
+ const params = {};
1126
+ const data = {};
1127
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
1128
+ }
1129
+ getFormsApiConfig() {
1130
+ const url = this._httpHelper.getUrl(this._httpHelper._config.ResourceUri.ConfigurationFormsApi);
1131
+ const opts = { method: "GET" };
1132
+ const params = {};
1133
+ const data = {};
1134
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
1135
+ }
1136
+ getObjectsApiConfig() {
1137
+ const url = this._httpHelper.getUrl(this._httpHelper._config.ResourceUri.ConfigurationObjectsApi);
1138
+ const opts = { method: "GET" };
1139
+ const params = {};
1140
+ const data = {};
1141
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
1142
+ }
1143
+ getStudioApiConfig() {
1144
+ const url = this._httpHelper.getUrl(this._httpHelper._config.ResourceUri.ConfigurationStudioApi);
1145
+ const opts = { method: "GET" };
1146
+ const params = {};
1147
+ const data = {};
1148
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
1149
+ }
1150
+ getNotificationsApiConfig() {
1151
+ const url = this._httpHelper.getUrl(this._httpHelper._config.ResourceUri.ConfigurationNotificationApi);
1152
+ const opts = { method: "GET" };
1153
+ const params = {};
1154
+ const data = {};
1155
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
1156
+ }
1157
+ };
1158
+
1159
+ // lib/vvRestApi/emailManager.js
1160
+ init_cjs_shims();
1161
+ var EmailManager = class {
1162
+ constructor(httpHelper) {
1163
+ this._httpHelper = httpHelper;
1164
+ }
1165
+ postEmails(params, data) {
1166
+ const url = this._httpHelper.getUrl(this._httpHelper._config.ResourceUri.Emails);
1167
+ const opts = { method: "POST" };
1168
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
1169
+ }
1170
+ postEmailsWithAttachments(params, data, fileObjs) {
1171
+ const url = this._httpHelper.getUrl(this._httpHelper._config.ResourceUri.Emails);
1172
+ const opts = { method: "POSTSTREAM" };
1173
+ return this._httpHelper.doVvClientRequest(url, opts, params, data, fileObjs);
1174
+ }
1175
+ };
1176
+
1177
+ // lib/vvRestApi/formsManager.js
1178
+ init_cjs_shims();
1179
+ var import_debug3 = __toESM(require("debug"), 1);
1180
+ var debug3 = (0, import_debug3.default)("visualvault:forms");
1181
+ var ReturnField = class {
1182
+ /** @type {string} */
1183
+ id;
1184
+ /** @type {string} */
1185
+ name;
1186
+ /** @type {*} */
1187
+ value;
1188
+ /** @type {boolean} */
1189
+ isError;
1190
+ /** @type {string} */
1191
+ errorMessage;
1192
+ /**
1193
+ * @param {string} id - Field ID
1194
+ * @param {string} name - Field name
1195
+ * @param {*} value - Field value
1196
+ * @param {boolean} isError - Whether field has an error
1197
+ * @param {string} errorMessage - Error message if any
1198
+ */
1199
+ constructor(id, name, value, isError, errorMessage) {
1200
+ this.id = id;
1201
+ this.name = name;
1202
+ this.value = value;
1203
+ this.isError = isError;
1204
+ this.errorMessage = errorMessage;
1205
+ }
1206
+ };
1207
+ var FormFieldCollection = class {
1208
+ /**
1209
+ * @param {Array<*>} ffColl - Array of form fields
1210
+ */
1211
+ constructor(ffColl) {
1212
+ this._ffColl = ffColl;
1213
+ }
1214
+ /**
1215
+ * Get a form field by name
1216
+ * @param {string} name - Field name to search for
1217
+ * @returns {*} The field or null if not found
1218
+ */
1219
+ getFormFieldByName(name) {
1220
+ const fieldName = name.toLowerCase();
1221
+ return this._ffColl.find(
1222
+ (field) => field.name.toLowerCase() === fieldName
1223
+ ) || null;
1224
+ }
1225
+ /**
1226
+ * Get a form field by ID
1227
+ * @param {string} id - Field ID to search for
1228
+ * @returns {*} The field or null if not found
1229
+ */
1230
+ getFormFieldById(id) {
1231
+ const fieldId = id.toLowerCase();
1232
+ return this._ffColl.find(
1233
+ (field) => field.id.toLowerCase() === fieldId
1234
+ ) || null;
1235
+ }
1236
+ /**
1237
+ * Get the array of all form fields
1238
+ * @returns {Array<*>} Array of form fields
1239
+ */
1240
+ getFieldArray() {
1241
+ return this._ffColl;
1242
+ }
1243
+ };
1244
+ var FormsManager = class {
1245
+ /**
1246
+ * @param {*} httpHelper - HTTP helper instance
1247
+ */
1248
+ constructor(httpHelper) {
1249
+ this._httpHelper = httpHelper;
1250
+ }
1251
+ returnField(id, name, value, isError, errorMessage) {
1252
+ return new ReturnField(id, name, value, isError, errorMessage);
1253
+ }
1254
+ getFormTemplates(params) {
1255
+ const url = this._httpHelper.getUrl(this._httpHelper._config.ResourceUri.FormTemplates);
1256
+ const opts = { method: "GET" };
1257
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
1258
+ }
1259
+ /**
1260
+ * @param {string} templateName
1261
+ * @returns {Promise<{formsManager: FormsManager, templateIdGuid: string, templateRevisionIdGuid: string, error?: string}>}
1262
+ */
1263
+ async getFormTemplateIdByName(templateName) {
1264
+ const params = {
1265
+ fields: "id, name, description, revision, revisionId",
1266
+ q: `name eq '${templateName}'`
1267
+ };
1268
+ const url = this._httpHelper.getUrl(this._httpHelper._config.ResourceUri.FormTemplates);
1269
+ const opts = { method: "GET" };
1270
+ try {
1271
+ const resp = await this._httpHelper.doVvClientRequest(url, opts, params, null);
1272
+ const templateResp = JSON.parse(resp);
1273
+ let templateId;
1274
+ let templateRevisionId;
1275
+ if (templateResp.data && templateResp.data.length > 0) {
1276
+ templateId = templateResp.data[0].id;
1277
+ templateRevisionId = templateResp.data[0].revisionId;
1278
+ }
1279
+ return {
1280
+ formsManager: this,
1281
+ templateIdGuid: templateId,
1282
+ templateRevisionIdGuid: templateRevisionId
1283
+ };
1284
+ } catch (error) {
1285
+ debug3('Failed to get form template by name "%s": %s', templateName, error.message);
1286
+ return {
1287
+ formsManager: this,
1288
+ templateIdGuid: "",
1289
+ templateRevisionIdGuid: "",
1290
+ error: error.message
1291
+ };
1292
+ }
1293
+ }
1294
+ async getForms(params, formTemplateId) {
1295
+ if (!this.isGuid(formTemplateId)) {
1296
+ const resp = await this.getFormTemplateIdByName(formTemplateId);
1297
+ const templateIdGuid = resp.templateIdGuid;
1298
+ const resourceUri = this._httpHelper._config.ResourceUri.Forms.replace("{id}", templateIdGuid);
1299
+ const url = this._httpHelper.getUrl(resourceUri);
1300
+ const opts = { method: "GET" };
1301
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
1302
+ } else {
1303
+ const resourceUri = this._httpHelper._config.ResourceUri.Forms.replace("{id}", formTemplateId);
1304
+ const url = this._httpHelper.getUrl(resourceUri);
1305
+ const opts = { method: "GET" };
1306
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
1307
+ }
1308
+ }
1309
+ setFieldImage(formId, fieldId, imageId) {
1310
+ const resourceUri = this._httpHelper._config.ResourceUri.FormInstanceImage.replace("{id}", formId);
1311
+ const url = this._httpHelper.getUrl(resourceUri);
1312
+ const data = { fieldId, imageId };
1313
+ const params = { fieldId, imageId };
1314
+ const opts = { method: "PUT" };
1315
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
1316
+ }
1317
+ importFormTemplate(data, formTemplateId, buffer) {
1318
+ const resourceUri = this._httpHelper._config.ResourceUri.FormTemplatesImport.replace("{id}", formTemplateId);
1319
+ const url = this._httpHelper.getUrl(resourceUri);
1320
+ const opts = { method: "PUTSTREAM" };
1321
+ return this._httpHelper.doVvClientRequest(url, opts, null, data, buffer);
1322
+ }
1323
+ async postForms(params, data, formTemplateId) {
1324
+ if (!this.isGuid(formTemplateId)) {
1325
+ const resp = await this.getFormTemplateIdByName(formTemplateId);
1326
+ const templateIdGuid = resp.templateIdGuid;
1327
+ const resourceUri = this._httpHelper._config.ResourceUri.Forms.replace("{id}", templateIdGuid);
1328
+ const url = this._httpHelper.getUrl(resourceUri);
1329
+ const opts = { method: "POST" };
1330
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
1331
+ } else {
1332
+ const resourceUri = this._httpHelper._config.ResourceUri.Forms.replace("{id}", formTemplateId);
1333
+ const url = this._httpHelper.getUrl(resourceUri);
1334
+ const opts = { method: "POST" };
1335
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
1336
+ }
1337
+ }
1338
+ async postFormRevision(params, data, formTemplateId, formId) {
1339
+ if (!this.isGuid(formTemplateId)) {
1340
+ const resp = await this.getFormTemplateIdByName(formTemplateId);
1341
+ const templateIdGuid = resp.templateIdGuid;
1342
+ const resourceUri = this._httpHelper._config.ResourceUri.Forms.replace("{id}", templateIdGuid);
1343
+ const url = this._httpHelper.getUrl(resourceUri + "/" + formId);
1344
+ const opts = { method: "POST" };
1345
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
1346
+ } else {
1347
+ const resourceUri = this._httpHelper._config.ResourceUri.Forms.replace("{id}", formTemplateId);
1348
+ const url = this._httpHelper.getUrl(resourceUri + "/" + formId);
1349
+ const opts = { method: "POST" };
1350
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
1351
+ }
1352
+ }
1353
+ postFormRevisionByFormId(params, data, formId) {
1354
+ const url = this._httpHelper.getUrl(this._httpHelper._config.ResourceUri.FormsId).replace("{id}", formId);
1355
+ const opts = { method: "POST" };
1356
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
1357
+ }
1358
+ updateFormInstanceOriginator(formInstanceId, newOriginatorUsID) {
1359
+ const resourceUri = this._httpHelper._config.ResourceUri.FormInstanceUpdateOriginator.replace("{id}", formInstanceId);
1360
+ const url = this._httpHelper.getUrl(resourceUri);
1361
+ const params = { userId: newOriginatorUsID };
1362
+ const data = null;
1363
+ const opts = { method: "PUT" };
1364
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
1365
+ }
1366
+ relateForm(formId, relateToId) {
1367
+ const resourceUri = this._httpHelper._config.ResourceUri.FormInstance.replace("{id}", formId);
1368
+ const url = this._httpHelper.getUrl(resourceUri + "/relateForm");
1369
+ const params = { relateToId };
1370
+ const data = null;
1371
+ const opts = { method: "PUT" };
1372
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
1373
+ }
1374
+ relateFormByDocId(formId, relateToDocId) {
1375
+ const resourceUri = this._httpHelper._config.ResourceUri.FormInstance.replace("{id}", formId);
1376
+ const url = this._httpHelper.getUrl(resourceUri + "/relateForm");
1377
+ const params = { relateToDocId };
1378
+ const data = null;
1379
+ const opts = { method: "PUT" };
1380
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
1381
+ }
1382
+ relateDocument(formId, relateToId) {
1383
+ const resourceUri = this._httpHelper._config.ResourceUri.FormInstance.replace("{id}", formId);
1384
+ const url = this._httpHelper.getUrl(resourceUri + "/relateDocument");
1385
+ const params = { relateToId };
1386
+ const data = null;
1387
+ const opts = { method: "PUT" };
1388
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
1389
+ }
1390
+ relateDocumentByDocId(formId, relateToDocId) {
1391
+ const resourceUri = this._httpHelper._config.ResourceUri.FormInstance.replace("{id}", formId);
1392
+ const url = this._httpHelper.getUrl(resourceUri + "/relateDocument");
1393
+ const params = { relateToDocId };
1394
+ const data = null;
1395
+ const opts = { method: "PUT" };
1396
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
1397
+ }
1398
+ relateProject(formId, relateToId) {
1399
+ const resourceUri = this._httpHelper._config.ResourceUri.FormInstance.replace("{id}", formId);
1400
+ const url = this._httpHelper.getUrl(resourceUri + "/relateProject");
1401
+ const params = { relateToId };
1402
+ const data = null;
1403
+ const opts = { method: "PUT" };
1404
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
1405
+ }
1406
+ relateProjectByName(formId, relateToProjectName) {
1407
+ const resourceUri = this._httpHelper._config.ResourceUri.FormInstance.replace("{id}", formId);
1408
+ const url = this._httpHelper.getUrl(resourceUri + "/relateProject");
1409
+ const params = { relateToProjectName };
1410
+ const data = null;
1411
+ const opts = { method: "PUT" };
1412
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
1413
+ }
1414
+ unrelateForm(formId, relateToId) {
1415
+ const resourceUri = this._httpHelper._config.ResourceUri.FormInstance.replace("{id}", formId);
1416
+ const url = this._httpHelper.getUrl(resourceUri + "/unrelateForm");
1417
+ const params = { relateToId };
1418
+ const data = null;
1419
+ const opts = { method: "PUT" };
1420
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
1421
+ }
1422
+ unrelateFormByDocId(formId, relateToDocId) {
1423
+ const resourceUri = this._httpHelper._config.ResourceUri.FormInstance.replace("{id}", formId);
1424
+ const url = this._httpHelper.getUrl(resourceUri + "/unrelateForm");
1425
+ const params = { relateToDocId };
1426
+ const data = null;
1427
+ const opts = { method: "PUT" };
1428
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
1429
+ }
1430
+ unrelateDocument(formId, relateToId) {
1431
+ const resourceUri = this._httpHelper._config.ResourceUri.FormInstance.replace("{id}", formId);
1432
+ const url = this._httpHelper.getUrl(resourceUri + "/unrelateDocument");
1433
+ const params = { relateToId };
1434
+ const data = null;
1435
+ const opts = { method: "PUT" };
1436
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
1437
+ }
1438
+ unrelateDocumentByDocId(formId, relateToDocId) {
1439
+ const resourceUri = this._httpHelper._config.ResourceUri.FormInstance.replace("{id}", formId);
1440
+ const url = this._httpHelper.getUrl(resourceUri + "/unrelateDocument");
1441
+ const params = { relateToDocId };
1442
+ const data = null;
1443
+ const opts = { method: "PUT" };
1444
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
1445
+ }
1446
+ unrelateProject(formId, relateToId) {
1447
+ const resourceUri = this._httpHelper._config.ResourceUri.FormInstance.replace("{id}", formId);
1448
+ const url = this._httpHelper.getUrl(resourceUri + "/unrelateProject");
1449
+ const params = { relateToId };
1450
+ const data = null;
1451
+ const opts = { method: "PUT" };
1452
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
1453
+ }
1454
+ unrelateProjectByName(formId, relateToProjectName) {
1455
+ const resourceUri = this._httpHelper._config.ResourceUri.FormInstance.replace("{id}", formId);
1456
+ const url = this._httpHelper.getUrl(resourceUri + "/unrelateProject");
1457
+ const params = { relateToProjectName };
1458
+ const data = null;
1459
+ const opts = { method: "PUT" };
1460
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
1461
+ }
1462
+ getFormRelatedDocs(formId, params) {
1463
+ const resourceUri = this._httpHelper._config.ResourceUri.FormInstanceRelatedDocs.replace("{id}", formId);
1464
+ const url = this._httpHelper.getUrl(resourceUri);
1465
+ const opts = { method: "GET" };
1466
+ if (params === void 0) {
1467
+ params = null;
1468
+ }
1469
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
1470
+ }
1471
+ getFormRelatedForms(formId, params) {
1472
+ const resourceUri = this._httpHelper._config.ResourceUri.FormInstanceRelatedForms.replace("{id}", formId);
1473
+ const url = this._httpHelper.getUrl(resourceUri);
1474
+ const opts = { method: "GET" };
1475
+ if (params === void 0) {
1476
+ params = null;
1477
+ }
1478
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
1479
+ }
1480
+ isGuid(stringToTest) {
1481
+ let testString = stringToTest;
1482
+ if (testString[0] === "{") {
1483
+ testString = testString.substring(1, testString.length - 1);
1484
+ }
1485
+ const regexGuid = /^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}$/gi;
1486
+ return regexGuid.test(testString);
1487
+ }
1488
+ getFormInstanceById(templateId, instanceId) {
1489
+ const resourceUri = this._httpHelper._config.ResourceUri.FormId.replace("{id}", templateId).replace("{formId}", instanceId);
1490
+ const url = this._httpHelper.getUrl(resourceUri);
1491
+ const opts = { method: "GET" };
1492
+ return this._httpHelper.doVvClientRequest(url, opts, null, null);
1493
+ }
1494
+ getFormInstancePDF(templateId, instanceId) {
1495
+ const resourceUri = this._httpHelper._config.ResourceUri.FormIdPdf.replace("{id}", templateId).replace("{formId}", instanceId);
1496
+ const url = this._httpHelper.getUrl(resourceUri);
1497
+ const opts = { method: "GETSTREAM" };
1498
+ return this._httpHelper.doVvClientRequest(url, opts, null, null);
1499
+ }
1500
+ getFormTemplateFields(templateId) {
1501
+ const resourceUri = this._httpHelper._config.ResourceUri.FormDesignerFormsTemplatesIdFields.replace("{id}", templateId);
1502
+ const url = this._httpHelper.getUrl(resourceUri);
1503
+ const opts = { method: "GET" };
1504
+ return this._httpHelper.doVvClientRequest(url, opts, null, null);
1505
+ }
1506
+ deleteFormInstance(instanceId) {
1507
+ const resourceUri = this._httpHelper._config.ResourceUri.FormInstance.replace("{id}", instanceId);
1508
+ const url = this._httpHelper.getUrl(resourceUri);
1509
+ const opts = { method: "DELETE" };
1510
+ return this._httpHelper.doVvClientRequest(url, opts, null, null);
1511
+ }
1512
+ releaseFormTemplate(formTemplateId) {
1513
+ const resourceUri = this._httpHelper._config.ResourceUri.FormTemplatesRelease.replace("{id}", formTemplateId);
1514
+ const url = this._httpHelper.getUrl(resourceUri);
1515
+ const opts = { method: "PUT" };
1516
+ return this._httpHelper.doVvClientRequest(url, opts, null, null);
1517
+ }
1518
+ };
1519
+
1520
+ // lib/vvRestApi/groupsManager.js
1521
+ init_cjs_shims();
1522
+ var GroupsManager = class {
1523
+ constructor(httpHelper) {
1524
+ this._httpHelper = httpHelper;
1525
+ }
1526
+ getGroups(params) {
1527
+ const resourceUri = this._httpHelper._config.ResourceUri.GetGroups;
1528
+ const url = this._httpHelper.getUrl(resourceUri);
1529
+ const opts = { method: "GET" };
1530
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
1531
+ }
1532
+ getGroupsUsers(params, groupId) {
1533
+ const resourceUri = this._httpHelper._config.ResourceUri.GroupsUsers.replace("{id}", groupId);
1534
+ const url = this._httpHelper.getUrl(resourceUri);
1535
+ const opts = { method: "GET" };
1536
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
1537
+ }
1538
+ getGroupUser(params, groupId, userId) {
1539
+ const resourceUri = this._httpHelper._config.ResourceUri.GroupsAddUser.replace("{groupId}", groupId).replace("{userId}", userId);
1540
+ const url = this._httpHelper.getUrl(resourceUri);
1541
+ const opts = { method: "GET" };
1542
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
1543
+ }
1544
+ addUserToGroup(params, groupId, userId) {
1545
+ const resourceUri = this._httpHelper._config.ResourceUri.GroupsAddUser.replace("{groupId}", groupId).replace("{userId}", userId);
1546
+ const url = this._httpHelper.getUrl(resourceUri);
1547
+ const opts = { method: "PUT" };
1548
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
1549
+ }
1550
+ removeUserFromGroup(params, groupId, userId) {
1551
+ const resourceUri = this._httpHelper._config.ResourceUri.GroupsAddUser.replace("{groupId}", groupId).replace("{userId}", userId);
1552
+ const url = this._httpHelper.getUrl(resourceUri);
1553
+ const opts = { method: "DELETE" };
1554
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
1555
+ }
1556
+ };
1557
+
1558
+ // lib/vvRestApi/libraryManager.js
1559
+ init_cjs_shims();
1560
+ var LibraryManager = class {
1561
+ constructor(httpHelper) {
1562
+ this._httpHelper = httpHelper;
1563
+ }
1564
+ getFolders(params) {
1565
+ const url = this._httpHelper.getUrl(this._httpHelper._config.ResourceUri.Folders);
1566
+ const opts = { method: "GET" };
1567
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
1568
+ }
1569
+ postFolderByPath(params, data, folderPath) {
1570
+ const url = this._httpHelper.getUrl(this._httpHelper._config.ResourceUri.Folders);
1571
+ data.folderpath = folderPath;
1572
+ const opts = { method: "POST" };
1573
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
1574
+ }
1575
+ // Valid fields to be defined on the "data" parameter to be updated on the folder: name, description
1576
+ putFolder(params, data, folderId) {
1577
+ const url = this._httpHelper.getUrl(this._httpHelper._config.ResourceUri.FoldersId.replace("{id}", folderId));
1578
+ const opts = { method: "PUT" };
1579
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
1580
+ }
1581
+ deleteFolder(folderId) {
1582
+ const url = this._httpHelper.getUrl(this._httpHelper._config.ResourceUri.FoldersId.replace("{id}", folderId));
1583
+ const opts = { method: "DELETE" };
1584
+ return this._httpHelper.doVvClientRequest(url, opts, null, null);
1585
+ }
1586
+ copyFolder(params, data) {
1587
+ const url = this._httpHelper.getUrl(this._httpHelper._config.ResourceUri.FoldersCopy);
1588
+ const opts = { method: "POST" };
1589
+ return this._httpHelper.doVvClientRequest(url, opts, null, data);
1590
+ }
1591
+ moveFolder(params, data) {
1592
+ const url = this._httpHelper.getUrl(this._httpHelper._config.ResourceUri.FoldersMove);
1593
+ const opts = { method: "PUT" };
1594
+ return this._httpHelper.doVvClientRequest(url, opts, null, data);
1595
+ }
1596
+ getDocuments(params, folderId) {
1597
+ const resourceUri = this._httpHelper._config.ResourceUri.Documents.replace("{id}", folderId);
1598
+ const url = this._httpHelper.getUrl(resourceUri);
1599
+ const opts = { method: "GET" };
1600
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
1601
+ }
1602
+ updateFolderIndexFieldOverrideSettings(folderId, fieldId, queryId, displayField, valueField, dropDownListId, required, defaultValue) {
1603
+ const data = {
1604
+ queryId,
1605
+ queryValueField: valueField,
1606
+ queryDisplayField: displayField,
1607
+ dropDownListId,
1608
+ required,
1609
+ defaultValue
1610
+ };
1611
+ const resourceUri = this._httpHelper._config.ResourceUri.FoldersIdIndexFieldsId.replace("{id}", folderId).replace("{indexFieldId}", fieldId);
1612
+ const url = this._httpHelper.getUrl(resourceUri);
1613
+ const opts = { method: "PUT" };
1614
+ return this._httpHelper.doVvClientRequest(url, opts, null, data);
1615
+ }
1616
+ getFolderIndexFields(params, folderId) {
1617
+ const resourceUri = this._httpHelper._config.ResourceUri.FolderIndexFields.replace("{id}", folderId);
1618
+ const url = this._httpHelper.getUrl(resourceUri);
1619
+ const opts = { method: "GET" };
1620
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
1621
+ }
1622
+ postFolderAlertSubscription(folderId, eventId, userId) {
1623
+ const resourceUri = this._httpHelper._config.ResourceUri.FolderAlertsId.replace("{folderId}", folderId).replace("{eventId}", eventId);
1624
+ const url = this._httpHelper.getUrl(resourceUri);
1625
+ const opts = { method: "POST" };
1626
+ const params = {
1627
+ usId: userId
1628
+ };
1629
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
1630
+ }
1631
+ deleteFolderAlertSubscription(folderId, eventId, userId) {
1632
+ const resourceUri = this._httpHelper._config.ResourceUri.FolderAlertsId.replace("{folderId}", folderId).replace("{eventId}", eventId);
1633
+ const url = this._httpHelper.getUrl(resourceUri);
1634
+ const opts = { method: "DELETE" };
1635
+ const params = {
1636
+ usId: userId
1637
+ };
1638
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
1639
+ }
1640
+ getFolderSecurityMembers(params, folderId) {
1641
+ const resourceUri = this._httpHelper._config.ResourceUri.FolderSecurity.replace("{folderId}", folderId);
1642
+ const url = this._httpHelper.getUrl(resourceUri);
1643
+ const opts = { method: "GET" };
1644
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
1645
+ }
1646
+ putFolderSecurityMember(folderId, memberId, memberType, securityRole, cascadeSecurityChanges) {
1647
+ const resourceUri = this._httpHelper._config.ResourceUri.FolderSecurityId.replace("{folderId}", folderId).replace("{memberId}", memberId);
1648
+ const url = this._httpHelper.getUrl(resourceUri);
1649
+ const opts = { method: "PUT" };
1650
+ const data = {
1651
+ memberType,
1652
+ securityRole,
1653
+ cascadeSecurityChanges
1654
+ };
1655
+ return this._httpHelper.doVvClientRequest(url, opts, null, data);
1656
+ }
1657
+ deleteFolderSecurityMember(folderId, memberId, cascadeSecurityChanges) {
1658
+ const resourceUri = this._httpHelper._config.ResourceUri.FolderSecurityId.replace("{folderId}", folderId).replace("{memberId}", memberId);
1659
+ const url = this._httpHelper.getUrl(resourceUri);
1660
+ const opts = { method: "DELETE" };
1661
+ const params = {
1662
+ cascadeSecurityChanges
1663
+ };
1664
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
1665
+ }
1666
+ };
1667
+
1668
+ // lib/vvRestApi/sitesManager.js
1669
+ init_cjs_shims();
1670
+ var SitesManager = class {
1671
+ constructor(httpHelper) {
1672
+ this._httpHelper = httpHelper;
1673
+ }
1674
+ getSites(params) {
1675
+ const url = this._httpHelper.getUrl(this._httpHelper._config.ResourceUri.Sites);
1676
+ const opts = { method: "GET" };
1677
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
1678
+ }
1679
+ postSites(params, data) {
1680
+ const resourceUri = this._httpHelper._config.ResourceUri.Sites;
1681
+ const url = this._httpHelper.getUrl(resourceUri);
1682
+ const opts = { method: "POST" };
1683
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
1684
+ }
1685
+ putSites(params, data, siteId) {
1686
+ const resourceUri = this._httpHelper._config.ResourceUri.Sites;
1687
+ const url = this._httpHelper.getUrl(resourceUri + "/" + siteId);
1688
+ const opts = { method: "PUT" };
1689
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
1690
+ }
1691
+ getGroups(params, siteId) {
1692
+ const resourceUri = this._httpHelper._config.ResourceUri.Groups.replace("{id}", siteId);
1693
+ const url = this._httpHelper.getUrl(resourceUri);
1694
+ const opts = { method: "GET" };
1695
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
1696
+ }
1697
+ postGroups(params, data, siteId) {
1698
+ const resourceUri = this._httpHelper._config.ResourceUri.Groups.replace("{id}", siteId);
1699
+ const url = this._httpHelper.getUrl(resourceUri);
1700
+ const opts = { method: "POST" };
1701
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
1702
+ }
1703
+ putGroups(params, data, siteId, grId) {
1704
+ const resourceUri = this._httpHelper._config.ResourceUri.Groups.replace("{id}", siteId);
1705
+ const url = this._httpHelper.getUrl(resourceUri + "/" + grId);
1706
+ const opts = { method: "PUT" };
1707
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
1708
+ }
1709
+ changeUserSite(userId, newSiteId) {
1710
+ const resourceUri = this._httpHelper._config.ResourceUri.ChangeUserSite;
1711
+ const url = this._httpHelper.getUrl(resourceUri);
1712
+ const opts = { method: "PUT" };
1713
+ const data = {
1714
+ UserId: userId,
1715
+ NewSiteId: newSiteId
1716
+ };
1717
+ return this._httpHelper.doVvClientRequest(url, opts, null, data);
1718
+ }
1719
+ };
1720
+
1721
+ // lib/vvRestApi/usersManager.js
1722
+ init_cjs_shims();
1723
+ var UsersManager = class {
1724
+ constructor(httpHelper) {
1725
+ this._httpHelper = httpHelper;
1726
+ }
1727
+ getUsers(params, siteId) {
1728
+ const resourceUri = this._httpHelper._config.ResourceUri.Users.replace("{id}", siteId);
1729
+ const url = this._httpHelper.getUrl(resourceUri);
1730
+ const opts = { method: "GET" };
1731
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
1732
+ }
1733
+ postUsers(params, data, siteId) {
1734
+ const resourceUri = this._httpHelper._config.ResourceUri.Users.replace("{id}", siteId);
1735
+ const url = this._httpHelper.getUrl(resourceUri);
1736
+ const opts = { method: "POST" };
1737
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
1738
+ }
1739
+ putUsers(params, data, siteId, usId) {
1740
+ const resourceUri = this._httpHelper._config.ResourceUri.Users.replace("{id}", siteId);
1741
+ const url = this._httpHelper.getUrl(resourceUri + "/" + usId);
1742
+ const opts = { method: "PUT" };
1743
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
1744
+ }
1745
+ putUsersEndpoint(params, data, usId) {
1746
+ const url = this._httpHelper.getUrl(this._httpHelper._config.ResourceUri.User + "/" + usId);
1747
+ const opts = { method: "PUT" };
1748
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
1749
+ }
1750
+ getUser(params) {
1751
+ const resourceUri = this._httpHelper._config.ResourceUri.User;
1752
+ const url = this._httpHelper.getUrl(resourceUri);
1753
+ const opts = { method: "GET" };
1754
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
1755
+ }
1756
+ getUserById(params, usId) {
1757
+ const resourceUri = this._httpHelper._config.ResourceUri.UserById.replace("{id}", usId);
1758
+ const url = this._httpHelper.getUrl(resourceUri);
1759
+ const opts = { method: "GET" };
1760
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
1761
+ }
1762
+ getUserGroups(params, usId) {
1763
+ const resourceUri = this._httpHelper._config.ResourceUri.UserGroups.replace("{id}", usId);
1764
+ const url = this._httpHelper.getUrl(resourceUri);
1765
+ const opts = { method: "GET" };
1766
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
1767
+ }
1768
+ getUserSupervisors(params, usId) {
1769
+ const resourceUri = this._httpHelper._config.ResourceUri.UserSupervisors.replace("{id}", usId);
1770
+ const url = this._httpHelper.getUrl(resourceUri);
1771
+ const opts = { method: "GET" };
1772
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
1773
+ }
1774
+ getUserSupervisees(params, usId) {
1775
+ const resourceUri = this._httpHelper._config.ResourceUri.UserSupervisees.replace("{id}", usId);
1776
+ const url = this._httpHelper.getUrl(resourceUri);
1777
+ const opts = { method: "GET" };
1778
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
1779
+ }
1780
+ getUserLoginToken(usId) {
1781
+ const resourceUri = this._httpHelper._config.ResourceUri.UserWebToken.replace("{id}", usId);
1782
+ const url = this._httpHelper.getUrl(resourceUri);
1783
+ const opts = { method: "GET" };
1784
+ const params = [];
1785
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
1786
+ }
1787
+ getUserJwt(audience) {
1788
+ const resourceUri = this._httpHelper._config.ResourceUri.UsersGetJwt;
1789
+ const url = this._httpHelper.getUrl(resourceUri);
1790
+ const opts = { method: "GET" };
1791
+ const params = {};
1792
+ if (audience) {
1793
+ params["audience"] = audience;
1794
+ }
1795
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
1796
+ }
1797
+ getCurrentUser() {
1798
+ const resourceUri = this._httpHelper._config.ResourceUri.UsersMe;
1799
+ const url = this._httpHelper.getUrl(resourceUri);
1800
+ const opts = { method: "GET" };
1801
+ const params = [];
1802
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
1803
+ }
1804
+ resetPassword(usId, sendEmail = true) {
1805
+ const resourceUri = this._httpHelper._config.ResourceUri.UsersPassword.replace("{id}", usId);
1806
+ const url = this._httpHelper.getUrl(resourceUri);
1807
+ const opts = { method: "PUT" };
1808
+ const params = [];
1809
+ const data = {
1810
+ resetPassword: true,
1811
+ sendEmail
1812
+ };
1813
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
1814
+ }
1815
+ updateUserId(usId, newUserId) {
1816
+ const resourceUri = this._httpHelper._config.ResourceUri.UsersIdUserId.replace("{id}", usId);
1817
+ const url = this._httpHelper.getUrl(resourceUri);
1818
+ const opts = { method: "PUT" };
1819
+ const params = [];
1820
+ const data = {
1821
+ userId: newUserId
1822
+ };
1823
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
1824
+ }
1825
+ };
1826
+
1827
+ // lib/vvRestApi/currentUserManager.js
1828
+ init_cjs_shims();
1829
+ var CurrentUserManager = class {
1830
+ constructor(httpHelper) {
1831
+ this._httpHelper = httpHelper;
1832
+ }
1833
+ /**
1834
+ * Gets the currently authenticated user's information.
1835
+ * @param {Object} [params] - Optional query parameters.
1836
+ * @returns {Promise<string>} A promise that resolves with the current user's information as a JSON string.
1837
+ */
1838
+ async getCurrentUser(params) {
1839
+ var resourceUri = this._httpHelper._config.ResourceUri.UsersMe;
1840
+ var url = this._httpHelper.getUrl(resourceUri);
1841
+ var opts = { method: "GET" };
1842
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
1843
+ }
1844
+ };
1845
+
1846
+ // lib/vvRestApi/scheduledProcessManager.js
1847
+ init_cjs_shims();
1848
+ var ScheduledProcessManager = class {
1849
+ constructor(httpHelper) {
1850
+ this._httpHelper = httpHelper;
1851
+ }
1852
+ postCompletion(id, action, result, message) {
1853
+ const url = this._httpHelper.getUrl(this._httpHelper._config.ResourceUri.ScheduledProcess) + "/" + id;
1854
+ const opts = { method: "POST" };
1855
+ const params = {
1856
+ action
1857
+ };
1858
+ if (result !== null && (typeof result === "boolean" || result.length > 0)) {
1859
+ params.result = result.toString();
1860
+ }
1861
+ if (message && message.length > 0) {
1862
+ params.message = message;
1863
+ }
1864
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
1865
+ }
1866
+ runAllScheduledProcesses() {
1867
+ const url = this._httpHelper.getUrl(this._httpHelper._config.ResourceUri.ScheduledProcess) + "/Run";
1868
+ const opts = { method: "PUT" };
1869
+ return this._httpHelper.doVvClientRequest(url, opts, null, null);
1870
+ }
1871
+ };
1872
+
1873
+ // lib/vvRestApi/customQueryManager.js
1874
+ init_cjs_shims();
1875
+ var CustomQueryManager = class {
1876
+ constructor(httpHelper) {
1877
+ this._httpHelper = httpHelper;
1878
+ }
1879
+ getCustomQueryResultsByName(queryName, params) {
1880
+ const url = this._httpHelper.getUrl(this._httpHelper._config.ResourceUri.CustomQuery);
1881
+ const opts = { method: "GET" };
1882
+ if (!params) {
1883
+ params = {};
1884
+ }
1885
+ params.queryName = queryName;
1886
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
1887
+ }
1888
+ getCustomQueryResultsById(id, params) {
1889
+ const url = this._httpHelper.getUrl(this._httpHelper._config.ResourceUri.CustomQuery + "/" + id);
1890
+ const opts = { method: "GET" };
1891
+ if (!params) {
1892
+ params = {};
1893
+ }
1894
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
1895
+ }
1896
+ };
1897
+
1898
+ // lib/vvRestApi/customerManager.js
1899
+ init_cjs_shims();
1900
+ var CustomerManager = class {
1901
+ constructor(httpHelper) {
1902
+ this._httpHelper = httpHelper;
1903
+ }
1904
+ createCustomerInvite(data) {
1905
+ const baseUrl = this._httpHelper._sessionToken.baseUrl;
1906
+ let url = baseUrl + "/api/v1/" + this._httpHelper._config.ResourceUri.CustomerInvite;
1907
+ url = url.replace(/\/api\/\//g, "/api/");
1908
+ url = url.replace(/\/v1\/\//g, "/v1/");
1909
+ const opts = { method: "POST" };
1910
+ return this._httpHelper.doVvClientRequest(url, opts, "", data);
1911
+ }
1912
+ assignUser(customerId, data) {
1913
+ const baseUrl = this._httpHelper._sessionToken.baseUrl;
1914
+ const url = baseUrl + "/api/v1/" + this._httpHelper._config.ResourceUri.CustomerAssignUser.replace("{customerId}", customerId);
1915
+ const opts = { method: "PUT" };
1916
+ return this._httpHelper.doVvClientRequest(url, opts, "", data);
1917
+ }
1918
+ };
1919
+
1920
+ // lib/vvRestApi/customerDatabaseManager.js
1921
+ init_cjs_shims();
1922
+ var import_debug4 = __toESM(require("debug"), 1);
1923
+ var debug4 = (0, import_debug4.default)("visualvault:customer-db");
1924
+ var CustomerDatabaseManager = class {
1925
+ constructor(httpHelper) {
1926
+ this._httpHelper = httpHelper;
1927
+ }
1928
+ assignUser(customerId, data) {
1929
+ const baseUrl = this._httpHelper._sessionToken.baseUrl;
1930
+ const url = baseUrl + "/api/v1/" + this._httpHelper._config.ResourceUri.CustomerDatabaseAssignUser.replace("{databaseId}", customerId);
1931
+ const opts = { method: "PUT" };
1932
+ return this._httpHelper.doVvClientRequest(url, opts, "", data);
1933
+ }
1934
+ removeUser(authenticationUserId, databaseId) {
1935
+ const baseUrl = this._httpHelper._sessionToken.baseUrl;
1936
+ let url = baseUrl + "/api/v1" + this._httpHelper._config.ResourceUri.UserDelete.replace("{databaseId}", databaseId);
1937
+ url = url.replace("{authenticationUserId}", authenticationUserId);
1938
+ debug4("Removing user %s from database %s: %s", authenticationUserId, databaseId, url);
1939
+ const opts = { method: "DELETE" };
1940
+ const params = [];
1941
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
1942
+ }
1943
+ };
1944
+
1945
+ // lib/vvRestApi/filesManager.js
1946
+ init_cjs_shims();
1947
+ var FilesManager = class {
1948
+ constructor(httpHelper) {
1949
+ this._httpHelper = httpHelper;
1950
+ }
1951
+ getFileBytesQuery(query) {
1952
+ const resourceUri = this._httpHelper._config.ResourceUri.FilesQuery + query;
1953
+ const url = this._httpHelper.getUrl(resourceUri);
1954
+ const opts = { method: "GETSTREAM" };
1955
+ return this._httpHelper.doVvClientRequest(url, opts, null, null);
1956
+ }
1957
+ getFileBytesId(id) {
1958
+ const resourceUri = this._httpHelper._config.ResourceUri.FilesId.replace("{id}", id);
1959
+ const url = this._httpHelper.getUrl(resourceUri);
1960
+ const opts = { method: "GETSTREAM" };
1961
+ return this._httpHelper.doVvClientRequest(url, opts, null, null);
1962
+ }
1963
+ postFile(data, buffer) {
1964
+ const resourceUri = this._httpHelper._config.ResourceUri.Files;
1965
+ const url = this._httpHelper.getUrl(resourceUri);
1966
+ const opts = { method: "POSTSTREAM" };
1967
+ return this._httpHelper.doVvClientRequest(url, opts, null, data, buffer);
1968
+ }
1969
+ };
1970
+
1971
+ // lib/vvRestApi/scriptsManager.js
1972
+ init_cjs_shims();
1973
+ var ScriptsManager = class {
1974
+ constructor(httpHelper) {
1975
+ this._httpHelper = httpHelper;
1976
+ }
1977
+ runWebService(serviceName, serviceData, usId) {
1978
+ let resourceUri = this._httpHelper._config.ResourceUri.Scripts + "?name=" + serviceName;
1979
+ if (typeof usId !== "undefined" && usId !== null) {
1980
+ resourceUri += `&usId=${usId}`;
1981
+ }
1982
+ const url = this._httpHelper.getUrl(resourceUri);
1983
+ const opts = { method: "POST" };
1984
+ return this._httpHelper.doVvClientRequest(url, opts, null, serviceData);
1985
+ }
1986
+ completeWorkflowWebService(executionId, workflowVariables) {
1987
+ const resourceUri = this._httpHelper._config.ResourceUri.ScriptsCompleteWf;
1988
+ const url = this._httpHelper.getUrl(resourceUri);
1989
+ const opts = { method: "POST" };
1990
+ const postData = {
1991
+ executionId,
1992
+ workflowVariables
1993
+ };
1994
+ return this._httpHelper.doVvClientRequest(url, opts, null, postData);
1995
+ }
1996
+ };
1997
+
1998
+ // lib/vvRestApi/documentsManager.js
1999
+ init_cjs_shims();
2000
+ var DocumentsManager = class {
2001
+ constructor(httpHelper) {
2002
+ this._httpHelper = httpHelper;
2003
+ }
2004
+ postDoc(data) {
2005
+ const resourceUri = this._httpHelper._config.ResourceUri.DocumentsPost;
2006
+ const url = this._httpHelper.getUrl(resourceUri);
2007
+ const opts = { method: "POST" };
2008
+ return this._httpHelper.doVvClientRequest(url, opts, null, data);
2009
+ }
2010
+ postDocWithFile(data, fileData) {
2011
+ const resourceUri = this._httpHelper._config.ResourceUri.DocumentsPost;
2012
+ const url = this._httpHelper.getUrl(resourceUri);
2013
+ const opts = { method: "POSTSTREAM" };
2014
+ return this._httpHelper.doVvClientRequest(url, opts, null, data, fileData);
2015
+ }
2016
+ copyDocument(params, data, documentId) {
2017
+ const resourceUri = this._httpHelper._config.ResourceUri.DocumentsIdCopy.replace("{id}", documentId);
2018
+ const url = this._httpHelper.getUrl(resourceUri);
2019
+ const opts = { method: "POST" };
2020
+ return this._httpHelper.doVvClientRequest(url, opts, null, data);
2021
+ }
2022
+ moveDocument(params, data, documentId) {
2023
+ const resourceUri = this._httpHelper._config.ResourceUri.DocumentsIdMove.replace("{id}", documentId);
2024
+ const url = this._httpHelper.getUrl(resourceUri);
2025
+ const opts = { method: "PUT" };
2026
+ return this._httpHelper.doVvClientRequest(url, opts, params, data);
2027
+ }
2028
+ deleteDocument(params, revisionId) {
2029
+ const resourceUri = this._httpHelper._config.ResourceUri.DocumentsId.replace("{id}", revisionId);
2030
+ const url = this._httpHelper.getUrl(resourceUri);
2031
+ const opts = { method: "DELETE" };
2032
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
2033
+ }
2034
+ getDocumentRevision(params, revisionId) {
2035
+ const resourceUri = this._httpHelper._config.ResourceUri.DocumentsId.replace("{id}", revisionId);
2036
+ const url = this._httpHelper.getUrl(resourceUri);
2037
+ const opts = { method: "GET" };
2038
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
2039
+ }
2040
+ getDocuments(params) {
2041
+ const resourceUri = this._httpHelper._config.ResourceUri.DocumentsPost;
2042
+ const url = this._httpHelper.getUrl(resourceUri);
2043
+ const opts = { method: "GET" };
2044
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
2045
+ }
2046
+ putDocumentIndexFields(data, documentId) {
2047
+ const resourceUri = this._httpHelper._config.ResourceUri.DocumentIndexFields.replace("{id}", documentId);
2048
+ const url = this._httpHelper.getUrl(resourceUri);
2049
+ const opts = { method: "PUT" };
2050
+ return this._httpHelper.doVvClientRequest(url, opts, null, data);
2051
+ }
2052
+ postDocumentAlertSubscription(documentId, eventId, userId) {
2053
+ const resourceUri = this._httpHelper._config.ResourceUri.DocumentAlertsId.replace("{documentId}", documentId).replace("{eventId}", eventId);
2054
+ const url = this._httpHelper.getUrl(resourceUri);
2055
+ const opts = { method: "POST" };
2056
+ const params = {
2057
+ usId: userId
2058
+ };
2059
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
2060
+ }
2061
+ deleteDocumentAlertSubscription(documentId, eventId, userId) {
2062
+ const resourceUri = this._httpHelper._config.ResourceUri.DocumentAlertsId.replace("{documentId}", documentId).replace("{eventId}", eventId);
2063
+ const url = this._httpHelper.getUrl(resourceUri);
2064
+ const opts = { method: "DELETE" };
2065
+ const params = {
2066
+ usId: userId
2067
+ };
2068
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
2069
+ }
2070
+ getDocumentRevisionOcrProperties(params, revisionId) {
2071
+ const resourceUri = this._httpHelper._config.ResourceUri.DocumentsIdOcr.replace("{id}", revisionId);
2072
+ const url = this._httpHelper.getUrl(resourceUri);
2073
+ const opts = { method: "GET" };
2074
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
2075
+ }
2076
+ relateDocuments(revisionId, relateToRevisionId, relateType) {
2077
+ const resourceUri = this._httpHelper._config.ResourceUri.DocumentsIdRelateDocument.replace("{id}", revisionId);
2078
+ const url = this._httpHelper.getUrl(resourceUri);
2079
+ const opts = { method: "PUT" };
2080
+ const data = {
2081
+ relateToId: relateToRevisionId,
2082
+ relateType
2083
+ };
2084
+ return this._httpHelper.doVvClientRequest(url, opts, null, data);
2085
+ }
2086
+ updateDocumentExpiration(documentId, expirationDate) {
2087
+ const resourceUri = this._httpHelper._config.ResourceUri.DocumentsIdExpiration.replace("{id}", documentId);
2088
+ const url = this._httpHelper.getUrl(resourceUri);
2089
+ const opts = { method: "PUT" };
2090
+ const data = {
2091
+ expirationDate
2092
+ };
2093
+ return this._httpHelper.doVvClientRequest(url, opts, null, data);
2094
+ }
2095
+ getDocumentWebDavUrl(documentId) {
2096
+ const resourceUri = this._httpHelper._config.ResourceUri.DocumentsWebDavUrl.replace("{id}", documentId);
2097
+ const url = this._httpHelper.getUrl(resourceUri);
2098
+ const opts = { method: "GET" };
2099
+ return this._httpHelper.doVvClientRequest(url, opts, null, null);
2100
+ }
2101
+ getDocumentWopiUrl(documentId) {
2102
+ const resourceUri = this._httpHelper._config.ResourceUri.DocumentsWopiUrl.replace("{id}", documentId);
2103
+ const url = this._httpHelper.getUrl(resourceUri);
2104
+ const opts = { method: "GET" };
2105
+ return this._httpHelper.doVvClientRequest(url, opts, null, null);
2106
+ }
2107
+ };
2108
+
2109
+ // lib/vvRestApi/projectsManager.js
2110
+ init_cjs_shims();
2111
+ var ProjectsManager = class {
2112
+ constructor(httpHelper) {
2113
+ this._httpHelper = httpHelper;
2114
+ }
2115
+ postProjectAlertSubscription(projectId, eventId, userId) {
2116
+ const resourceUri = this._httpHelper._config.ResourceUri.ProjectAlertsId.replace("{projectId}", projectId).replace("{eventId}", eventId);
2117
+ const url = this._httpHelper.getUrl(resourceUri);
2118
+ const opts = { method: "POST" };
2119
+ const params = {
2120
+ usId: userId
2121
+ };
2122
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
2123
+ }
2124
+ deleteProjectAlertSubscription(projectId, eventId, userId) {
2125
+ const resourceUri = this._httpHelper._config.ResourceUri.ProjectAlertsId.replace("{projectId}", projectId).replace("{eventId}", eventId);
2126
+ const url = this._httpHelper.getUrl(resourceUri);
2127
+ const opts = { method: "DELETE" };
2128
+ const params = {
2129
+ usId: userId
2130
+ };
2131
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
2132
+ }
2133
+ };
2134
+
2135
+ // lib/vvRestApi/indexFieldsManager.js
2136
+ init_cjs_shims();
2137
+ var IndexFieldsManager = class {
2138
+ constructor(httpHelper) {
2139
+ this._httpHelper = httpHelper;
2140
+ }
2141
+ getIndexFields(params) {
2142
+ const resourceUri = this._httpHelper._config.ResourceUri.IndexFields;
2143
+ const url = this._httpHelper.getUrl(resourceUri);
2144
+ const opts = { method: "GET" };
2145
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
2146
+ }
2147
+ };
2148
+
2149
+ // lib/vvRestApi/outsideProcessesManager.js
2150
+ init_cjs_shims();
2151
+ var OutsideProcessesManager = class {
2152
+ constructor(httpHelper) {
2153
+ this._httpHelper = httpHelper;
2154
+ }
2155
+ getOutsideProcesses(params) {
2156
+ const resourceUri = this._httpHelper._config.ResourceUri.OutsideProcesses;
2157
+ const url = this._httpHelper.getUrl(resourceUri);
2158
+ const opts = { method: "GET" };
2159
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
2160
+ }
2161
+ };
2162
+
2163
+ // lib/vvRestApi/securityMembersManager.js
2164
+ init_cjs_shims();
2165
+ var SecurityMembersManager = class {
2166
+ constructor(httpHelper) {
2167
+ this._httpHelper = httpHelper;
2168
+ }
2169
+ addSecurityMember(parentId, memberId, roleType, isGroup) {
2170
+ const resourceUri = this._httpHelper._config.ResourceUri.SecurityMembers;
2171
+ const url = this._httpHelper.getUrl(resourceUri);
2172
+ const opts = { method: "POST" };
2173
+ const postData = {
2174
+ parentId,
2175
+ memberId,
2176
+ role: roleType,
2177
+ isGroup
2178
+ };
2179
+ return this._httpHelper.doVvClientRequest(url, opts, null, postData);
2180
+ }
2181
+ getSecurityMembersForParentId(parentId) {
2182
+ const resourceUri = this._httpHelper._config.ResourceUri.SecurityMembers;
2183
+ const url = this._httpHelper.getUrl(resourceUri);
2184
+ const opts = { method: "GET" };
2185
+ const params = {
2186
+ parentId
2187
+ };
2188
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
2189
+ }
2190
+ removeSecurityMember(parentId, memberId) {
2191
+ const resourceUri = this._httpHelper._config.ResourceUri.SecurityMembers;
2192
+ const url = this._httpHelper.getUrl(resourceUri);
2193
+ const opts = { method: "DELETE" };
2194
+ const params = {
2195
+ parentId,
2196
+ memberId
2197
+ };
2198
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
2199
+ }
2200
+ updateSecurityMember(parentId, memberId, roleType) {
2201
+ const resourceUri = this._httpHelper._config.ResourceUri.SecurityMembers;
2202
+ const url = this._httpHelper.getUrl(resourceUri);
2203
+ const opts = { method: "PUT" };
2204
+ const postData = {
2205
+ parentId,
2206
+ memberId,
2207
+ role: roleType
2208
+ };
2209
+ return this._httpHelper.doVvClientRequest(url, opts, null, postData);
2210
+ }
2211
+ };
2212
+
2213
+ // lib/vvRestApi/layoutsManager.js
2214
+ init_cjs_shims();
2215
+ var LayoutsManager = class {
2216
+ constructor(httpHelper) {
2217
+ this._httpHelper = httpHelper;
2218
+ }
2219
+ getLayout() {
2220
+ const resourceUri = this._httpHelper._config.ResourceUri.Layout;
2221
+ const url = this._httpHelper.getUrl(resourceUri);
2222
+ const opts = { method: "GET" };
2223
+ return this._httpHelper.doVvClientRequest(url, opts, {}, null);
2224
+ }
2225
+ };
2226
+
2227
+ // lib/vvRestApi/reportsManager.js
2228
+ init_cjs_shims();
2229
+ var ReportsManager = class {
2230
+ constructor(httpHelper) {
2231
+ this._httpHelper = httpHelper;
2232
+ }
2233
+ getReportPDF(reportId, params) {
2234
+ const resourceUri = this._httpHelper._config.ResourceUri.ReportServerPDF.replace("{id}", reportId);
2235
+ const url = this._httpHelper.getUrl(resourceUri);
2236
+ const opts = { method: "GETSTREAM" };
2237
+ return this._httpHelper.doVvClientRequest(url, opts, params, null);
2238
+ }
2239
+ };
2240
+
2241
+ // lib/VVRestApi.js
2242
+ var debug5 = (0, import_debug5.default)("visualvault:api");
2243
+ var __filename7 = (0, import_url6.fileURLToPath)(importMetaUrl);
2244
+ var __dirname6 = import_path6.default.dirname(__filename7);
2245
+ var VVClient = class {
2246
+ /** @type {*} */
2247
+ constants;
2248
+ /** @type {*} */
2249
+ configuration;
2250
+ /** @type {*} */
2251
+ customQuery;
2252
+ /** @type {*} */
2253
+ documents;
2254
+ /** @type {*} */
2255
+ email;
2256
+ /** @type {*} */
2257
+ files;
2258
+ /** @type {*} */
2259
+ forms;
2260
+ /** @type {*} */
2261
+ groups;
2262
+ /** @type {*} */
2263
+ library;
2264
+ /** @type {*} */
2265
+ sites;
2266
+ /** @type {*} */
2267
+ users;
2268
+ /** @type {*} */
2269
+ scheduledProcess;
2270
+ /** @type {*} */
2271
+ scripts;
2272
+ /** @type {*} */
2273
+ projects;
2274
+ /** @type {*} */
2275
+ customer;
2276
+ /** @type {*} */
2277
+ customerDatabase;
2278
+ /** @type {*} */
2279
+ indexFields;
2280
+ /** @type {*} */
2281
+ outsideProcesses;
2282
+ /** @type {*} */
2283
+ securityMembers;
2284
+ /** @type {*} */
2285
+ layouts;
2286
+ /** @type {*} */
2287
+ reports;
2288
+ /**
2289
+ * @param {*} sessionToken - Session token from authentication
2290
+ */
2291
+ constructor(sessionToken) {
2292
+ this.yamlConfig = import_js_yaml7.default.load(import_fs7.default.readFileSync(import_path6.default.join(__dirname6, "config.yml"), "utf8"));
2293
+ this._httpHelper = new common_default.httpHelper(sessionToken, this.yamlConfig);
2294
+ this.constants = new Constants();
2295
+ this.configuration = new ConfigurationManager(this._httpHelper);
2296
+ this.customQuery = new CustomQueryManager(this._httpHelper);
2297
+ this.documents = new DocumentsManager(this._httpHelper);
2298
+ this.email = new EmailManager(this._httpHelper);
2299
+ this.files = new FilesManager(this._httpHelper);
2300
+ this.forms = new FormsManager(this._httpHelper);
2301
+ this.groups = new GroupsManager(this._httpHelper);
2302
+ this.library = new LibraryManager(this._httpHelper);
2303
+ this.sites = new SitesManager(this._httpHelper);
2304
+ this.users = new UsersManager(this._httpHelper);
2305
+ this.currentUser = new CurrentUserManager(this._httpHelper);
2306
+ this.scheduledProcess = new ScheduledProcessManager(this._httpHelper);
2307
+ this.scripts = new ScriptsManager(this._httpHelper);
2308
+ this.projects = new ProjectsManager(this._httpHelper);
2309
+ this.customer = new CustomerManager(this._httpHelper);
2310
+ this.customerDatabase = new CustomerDatabaseManager(this._httpHelper);
2311
+ this.indexFields = new IndexFieldsManager(this._httpHelper);
2312
+ this.outsideProcesses = new OutsideProcessesManager(this._httpHelper);
2313
+ this.securityMembers = new SecurityMembersManager(this._httpHelper);
2314
+ this.layouts = new LayoutsManager(this._httpHelper);
2315
+ this.reports = new ReportsManager(this._httpHelper);
2316
+ this.docApi = null;
2317
+ this.formsApi = null;
2318
+ this.objectsApi = null;
2319
+ this.studioApi = null;
2320
+ this.notificationsApi = null;
2321
+ }
2322
+ async createDocApi(sessionToken) {
2323
+ const docApiConfigResponse = JSON.parse(await this.configuration.getDocApiConfig());
2324
+ if (docApiConfigResponse && docApiConfigResponse["data"]) {
2325
+ const docApiSession = sessionToken.createCopy();
2326
+ docApiSession.baseUrl = docApiConfigResponse.data["apiUrl"];
2327
+ docApiSession.apiUrl = this.yamlConfig.DocApiUri;
2328
+ if (docApiSession["tokenType"] == "jwt") {
2329
+ this.docApi = new DocApi_default(docApiSession, docApiConfigResponse.data);
2330
+ } else if (this.users) {
2331
+ const jwtResponse = JSON.parse(await this.users.getUserJwt(docApiSession.audience));
2332
+ if (jwtResponse["data"] && jwtResponse["data"]["token"]) {
2333
+ docApiSession.convertToJwt(jwtResponse["data"]);
2334
+ this.docApi = new DocApi_default(docApiSession, docApiConfigResponse.data);
2335
+ }
2336
+ }
2337
+ }
2338
+ }
2339
+ async createFormsApi(sessionToken) {
2340
+ const formsApiConfigResponse = JSON.parse(await this.configuration.getFormsApiConfig());
2341
+ if (formsApiConfigResponse && formsApiConfigResponse["data"]) {
2342
+ const formsApiSession = sessionToken.createCopy();
2343
+ formsApiSession.baseUrl = formsApiConfigResponse.data["formsApiUrl"];
2344
+ formsApiSession.apiUrl = this.yamlConfig.FormsApiUri;
2345
+ if (formsApiSession["tokenType"] == "jwt") {
2346
+ this.formsApi = new FormsApi_default(formsApiSession, formsApiConfigResponse.data);
2347
+ } else if (this.users) {
2348
+ const jwtResponse = JSON.parse(await this.users.getUserJwt(formsApiSession.audience));
2349
+ if (jwtResponse["data"] && jwtResponse["data"]["token"]) {
2350
+ formsApiSession.convertToJwt(jwtResponse["data"]);
2351
+ this.formsApi = new FormsApi_default(formsApiSession, formsApiConfigResponse.data);
2352
+ }
2353
+ }
2354
+ }
2355
+ }
2356
+ async createObjectsApi(sessionToken) {
2357
+ const objectsApiConfigResponse = JSON.parse(await this.configuration.getObjectsApiConfig());
2358
+ if (objectsApiConfigResponse && objectsApiConfigResponse["data"]) {
2359
+ const objectsApiSession = sessionToken.createCopy();
2360
+ objectsApiSession.baseUrl = objectsApiConfigResponse.data["apiUrl"];
2361
+ objectsApiSession.apiUrl = "";
2362
+ if (objectsApiSession["tokenType"] == "jwt") {
2363
+ this.objectsApi = new ObjectsApi_default(objectsApiSession, objectsApiConfigResponse.data);
2364
+ } else if (this.users) {
2365
+ const jwtResponse = JSON.parse(await this.users.getUserJwt(objectsApiSession.audience));
2366
+ if (jwtResponse["data"] && jwtResponse["data"]["token"]) {
2367
+ objectsApiSession.convertToJwt(jwtResponse["data"]);
2368
+ this.objectsApi = new ObjectsApi_default(objectsApiSession, objectsApiConfigResponse.data);
2369
+ }
2370
+ }
2371
+ }
2372
+ }
2373
+ async createStudioApi(sessionToken) {
2374
+ const studioApiConfigResponse = JSON.parse(await this.configuration.getStudioApiConfig());
2375
+ if (studioApiConfigResponse && studioApiConfigResponse["data"]) {
2376
+ const studioApiSession = sessionToken.createCopy();
2377
+ studioApiSession.baseUrl = studioApiConfigResponse.data["studioApiUrl"];
2378
+ studioApiSession.apiUrl = "";
2379
+ if (studioApiSession["tokenType"] == "jwt") {
2380
+ this.studioApi = new StudioApi_default(studioApiSession, studioApiConfigResponse.data);
2381
+ } else if (this.users) {
2382
+ const jwtResponse = JSON.parse(await this.users.getUserJwt(studioApiSession.audience));
2383
+ if (jwtResponse["data"] && jwtResponse["data"]["token"]) {
2384
+ studioApiSession.convertToJwt(jwtResponse["data"]);
2385
+ this.studioApi = new StudioApi_default(studioApiSession, studioApiConfigResponse.data);
2386
+ }
2387
+ }
2388
+ }
2389
+ }
2390
+ async createNotificationsApi(sessionToken) {
2391
+ const notificationsApiConfigResponse = JSON.parse(await this.configuration.getNotificationsApiConfig());
2392
+ if (notificationsApiConfigResponse && notificationsApiConfigResponse["data"]) {
2393
+ const notificationsApiSession = sessionToken.createCopy();
2394
+ notificationsApiSession.baseUrl = notificationsApiConfigResponse.data["apiUrl"];
2395
+ notificationsApiSession.apiUrl = this.yamlConfig.NotificationsApiUri;
2396
+ if (notificationsApiSession["tokenType"] == "jwt") {
2397
+ this.notificationsApi = new NotificationsApi_default(notificationsApiSession, notificationsApiConfigResponse.data);
2398
+ } else if (this.users) {
2399
+ const jwtResponse = JSON.parse(await this.users.getUserJwt(notificationsApiSession.audience));
2400
+ if (jwtResponse["data"] && jwtResponse["data"]["token"]) {
2401
+ notificationsApiSession.convertToJwt(jwtResponse["data"]);
2402
+ this.notificationsApi = new NotificationsApi_default(notificationsApiSession, notificationsApiConfigResponse.data);
2403
+ }
2404
+ }
2405
+ }
2406
+ }
2407
+ async _convertToJwt(sessionToken) {
2408
+ const jwtResponse = JSON.parse(await this.users.getUserJwt(sessionToken.audience));
2409
+ if (jwtResponse["data"] && jwtResponse["data"]["token"]) {
2410
+ sessionToken.convertToJwt(jwtResponse["data"]);
2411
+ } else {
2412
+ throw new Error("Failed to get JWT: API response missing data.token property");
2413
+ }
2414
+ }
2415
+ endsWith(source, suffix) {
2416
+ return source.indexOf(suffix, source.length - suffix.length) !== -1;
2417
+ }
2418
+ /**
2419
+ * Get the current security token
2420
+ * @returns {string} The access token
2421
+ */
2422
+ getSecurityToken() {
2423
+ return this._httpHelper._sessionToken.accessToken;
2424
+ }
2425
+ /**
2426
+ * Check if the client is authenticated
2427
+ * @returns {boolean} True if authenticated
2428
+ */
2429
+ isAuthenticated() {
2430
+ return this._httpHelper._sessionToken.isAuthenticated;
2431
+ }
2432
+ /**
2433
+ * Get the base URL
2434
+ * @returns {string} The base URL
2435
+ */
2436
+ getBaseUrl() {
2437
+ return this._httpHelper._sessionToken.baseUrl;
2438
+ }
2439
+ };
2440
+ var Authorize2 = class extends common_default.authorize {
2441
+ /**
2442
+ * Authenticate and get a VaultApi client instance
2443
+ * @param {string} clientId - OAuth client ID
2444
+ * @param {string} clientSecret - OAuth client secret
2445
+ * @param {string} userId - User username
2446
+ * @param {string} password - User password
2447
+ * @param {string} audience - OAuth audience
2448
+ * @param {string} baseVaultUrl - VisualVault base URL
2449
+ * @param {string} customerAlias - Customer alias
2450
+ * @param {string} databaseAlias - Database alias
2451
+ * @returns {Promise<VVClient>} Authenticated client instance
2452
+ */
2453
+ async getVaultApi(clientId, clientSecret, userId, password, audience, baseVaultUrl, customerAlias, databaseAlias) {
2454
+ debug5("getVaultApi called for user: %s, customer: %s/%s", userId, customerAlias, databaseAlias);
2455
+ const config = this.jsyaml.load(this.fs.readFileSync(__dirname6 + "/config.yml", "utf8"));
2456
+ if (this.endsWith(baseVaultUrl, "/")) {
2457
+ baseVaultUrl = baseVaultUrl.substring(0, baseVaultUrl.length - 1);
2458
+ }
2459
+ const apiUrl = config.ApiUri.replace("{custalias}", customerAlias).replace("{custdbalias}", databaseAlias);
2460
+ const authenticationUrl = config.AutheticateUri;
2461
+ const sessionToken = await this.acquireSecurityToken(clientId, clientSecret, userId, password, audience, baseVaultUrl, apiUrl, customerAlias, databaseAlias, authenticationUrl);
2462
+ const client = new VVClient(sessionToken);
2463
+ try {
2464
+ await client._convertToJwt(sessionToken);
2465
+ await Promise.all([
2466
+ client.createDocApi(sessionToken),
2467
+ client.createFormsApi(sessionToken),
2468
+ client.createObjectsApi(sessionToken),
2469
+ client.createStudioApi(sessionToken),
2470
+ client.createNotificationsApi(sessionToken)
2471
+ ]);
2472
+ return client;
2473
+ } catch (error) {
2474
+ debug5("Failed to convert to JWT or create specialized APIs: %s", error.message);
2475
+ return client;
2476
+ }
2477
+ }
2478
+ /**
2479
+ * Get a VaultApi client from an existing JWT token
2480
+ * @param {string} jwt - JWT authentication token
2481
+ * @param {string} baseVaultUrl - VisualVault base URL
2482
+ * @param {string} customerAlias - Customer alias
2483
+ * @param {string} databaseAlias - Database alias
2484
+ * @param {Date} expirationDate - Token expiration date
2485
+ * @returns {Promise<VVClient>} Authenticated client instance
2486
+ */
2487
+ async getVaultApiFromJwt(jwt, baseVaultUrl, customerAlias, databaseAlias, expirationDate) {
2488
+ debug5("getVaultApiFromJwt called for customer: %s/%s", customerAlias, databaseAlias);
2489
+ const config = this.jsyaml.load(this.fs.readFileSync(__dirname6 + "/config.yml", "utf8"));
2490
+ if (this.endsWith(baseVaultUrl, "/")) {
2491
+ baseVaultUrl = baseVaultUrl.substring(0, baseVaultUrl.length - 1);
2492
+ }
2493
+ const apiUrl = config.ApiUri.replace("{custalias}", customerAlias).replace("{custdbalias}", databaseAlias);
2494
+ const authenticationUrl = apiUrl + config.ResourceUri.UsersGetJwt;
2495
+ if (expirationDate && expirationDate >= new Date((/* @__PURE__ */ new Date()).getTime() + 30 * 1e3)) {
2496
+ const sessionToken = new common_default.sessionToken();
2497
+ sessionToken.accessToken = jwt;
2498
+ sessionToken.baseUrl = baseVaultUrl;
2499
+ sessionToken.apiUrl = apiUrl;
2500
+ sessionToken.authenticationUrl = authenticationUrl;
2501
+ sessionToken.customerAlias = customerAlias;
2502
+ sessionToken.databaseAlias = databaseAlias;
2503
+ sessionToken.expirationDate = expirationDate;
2504
+ sessionToken.isAuthenticated = true;
2505
+ sessionToken.isJwt = true;
2506
+ const client = new VVClient(sessionToken);
2507
+ return Promise.all([
2508
+ client.createDocApi(sessionToken),
2509
+ client.createFormsApi(sessionToken),
2510
+ client.createObjectsApi(sessionToken),
2511
+ client.createStudioApi(sessionToken)
2512
+ ]).then(() => client).catch((error) => {
2513
+ debug5("Failed to create specialized APIs: %s", error.message);
2514
+ return client;
2515
+ });
2516
+ } else {
2517
+ const token = await this.acquireJwt(jwt, baseVaultUrl, apiUrl, authenticationUrl, customerAlias, databaseAlias);
2518
+ const client = new VVClient(token);
2519
+ try {
2520
+ await Promise.all([
2521
+ client.createDocApi(token),
2522
+ client.createFormsApi(token),
2523
+ client.createObjectsApi(token),
2524
+ client.createStudioApi(token)
2525
+ ]);
2526
+ return client;
2527
+ } catch (error) {
2528
+ debug5("Failed to create specialized APIs: %s", error.message);
2529
+ return client;
2530
+ }
2531
+ }
2532
+ }
2533
+ endsWith(source, suffix) {
2534
+ return source.indexOf(suffix, source.length - suffix.length) !== -1;
2535
+ }
2536
+ };
2537
+ var forms = {
2538
+ returnField: ReturnField,
2539
+ formFieldCollection: FormFieldCollection
2540
+ };
2541
+ var VVRestApi_default = {
2542
+ vvClient: VVClient,
2543
+ authorize: Authorize2,
2544
+ forms
2545
+ };
2546
+ // Annotate the CommonJS export names for ESM import in node:
2547
+ 0 && (module.exports = {
2548
+ Authorize,
2549
+ VVClient,
2550
+ forms
2551
+ });
2552
+ //# sourceMappingURL=VVRestApi.cjs.map