@js4cytoscape/ndex-client 0.6.0-alpha.1 → 0.6.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/NDEx.js.bak DELETED
@@ -1,1107 +0,0 @@
1
- import { default as axios } from 'axios';
2
-
3
- const CX1_HEADER = {
4
- numberVerification: [{
5
- "longNumber": 283213721732712
6
- }]
7
- };
8
-
9
- /**
10
- * NDEx client class.
11
- */
12
- class NDEx {
13
- constructor(hostprefix) {
14
- if (hostprefix === undefined || hostprefix === null || hostprefix === '') {
15
- throw new Error('NDEx server host name or endpoint base URL is required in client constructor.');
16
- }
17
-
18
- // axios needs http to be at the front of the url.
19
- // Otherwise any request will be redirected to localhost and fail
20
- // with an ambiguous reason
21
- let httpRegex = new RegExp("^(http|https)://", "i");
22
- if (!httpRegex.test(hostprefix)) {
23
- // throw new Error(`"http://" or "https://" must be prefixed to the input url: ${hostprefix}`);
24
- // we assume it is a host name
25
- if ( hostprefix.indexOf('/') > -1 )
26
- throw new Error ('"/" are not allowed in host name.');
27
- hostprefix = "https://"+ hostprefix + "/v2";
28
- }
29
-
30
- this._host = hostprefix;
31
- this._v3baseURL = this._host.substring(0,this.host.lastIndexOf('v2')) + 'v3';
32
- }
33
- get host() { return this._host;}
34
-
35
- get googleAuth() {
36
- return this._googleAuth;
37
- }
38
-
39
- SetGoogleAuth(googleAuthObj) {
40
- if (googleAuthObj !== undefined) {
41
- this._googleAuth = googleAuthObj;
42
- this._authType = 'g'; // valid values are 'g','b' or undefined
43
- }
44
- }
45
-
46
- setAuthToken(authToken) {
47
- if (authToken !== undefined ) {
48
- this._authToken = authToken;
49
- this._authType = 'g'; // valid values are 'g','b' or undefined
50
- }
51
- }
52
-
53
- get authenticationType() {
54
- return this._authType;
55
- }
56
-
57
- get username() {
58
- return this._username;
59
- }
60
-
61
- // get authStr() { return this._authStr;}
62
- get password() { return this._password;}
63
-
64
- setBasicAuth(accountname, password) {
65
- if (accountname !== undefined && accountname != null && accountname !== '') {
66
- this._username = accountname;
67
- this._password = password;
68
- this._authType = 'b';
69
- // this._authStr = 'Basic ' + btoa(username + ':' + password);
70
- return;
71
- }
72
- this._username = undefined;
73
- this._password = undefined;
74
- this._authType = undefined;
75
- // this._authStr = undefined;
76
- }
77
-
78
- _httpGetOpenObj(URL) {
79
- let APIEndPointPrefix = this.host ;
80
-
81
- return new Promise(function (resolve, reject) {
82
- axios({
83
- method: 'get',
84
- url: URL,
85
- baseURL: APIEndPointPrefix
86
- }).then((response) => {
87
- if (response.status === 200) {
88
- return resolve(response.data);
89
- }
90
- return reject(response);
91
- },
92
- (response) =>{return reject(response);}
93
- );
94
- });
95
- }
96
-
97
- // access endpoints that supports authentication
98
-
99
- _getIdToken() {
100
- return this._authToken ? this._authToken : this._googleAuth.getAuthInstance().currentUser.get().getAuthResponse().id_token;
101
- }
102
-
103
- _setAuthHeader(config) {
104
-
105
- if (config['headers'] === undefined) {config['headers'] = {};}
106
- config['headers']['setAuthHeader'] = false;
107
-
108
- if (this._authType === 'b') {
109
- config ['auth'] = { username: this.username,
110
- password: this.password};
111
- } else if (this.authenticationType === 'g') {
112
- config['headers']['Authorization'] = 'Bearer ' + this._getIdToken();
113
- }
114
- }
115
-
116
- _httpGetProtectedObjAux (prefix, URL, parameters) {
117
-
118
- let config = {
119
- method: 'get',
120
- url: URL,
121
- baseURL: prefix
122
- };
123
-
124
- this._setAuthHeader(config);
125
-
126
- if (parameters !== undefined) {
127
- config['params'] = parameters;
128
- }
129
- return new Promise(function (resolve, reject) {
130
- axios(config).then((response) => {
131
- if (response.status === 200) {
132
- return resolve(response.data);
133
- }
134
- return reject(response);
135
- },
136
- (response) => {
137
- return reject(response);
138
- }
139
- );
140
- });
141
- }
142
-
143
- _httpGetV3ProtectedObj(URL, parameters) {
144
- return this._httpGetProtectedObjAux(this._v3baseURL, URL, parameters);
145
- }
146
-
147
- _httpGetProtectedObj(URL, parameters) {
148
- return this._httpGetProtectedObjAux(this.host, URL,parameters);
149
- }
150
-
151
- _httpPostProtectedObjAux(prefix, URL, parameters, data) {
152
- let config = {
153
- method: 'post',
154
- url: URL,
155
- baseURL: prefix
156
- };
157
-
158
- this._setAuthHeader(config);
159
-
160
- if (parameters !== undefined) {
161
- config['params'] = parameters;
162
- }
163
-
164
- config.data = data;
165
- return new Promise(function (resolve, reject) {
166
- axios(config).then((response) => {
167
- if (response.status >= 200 && response.status <= 299) {
168
- return resolve(response.data);
169
- }
170
- return reject(response);
171
- },
172
- (response) => {
173
- return reject(response);
174
- }
175
- );
176
- });
177
- }
178
-
179
- _httpPostProtectedObj(URL, parameters, data) {
180
- return this._httpPostProtectedObjAux(this.host,URL,parameters, data);
181
- }
182
-
183
- _httpPostV3ProtectedObj(URL, parameters, data) {
184
- return this._httpPostProtectedObjAux(this._v3baseURL,URL,parameters, data);
185
- }
186
-
187
- _httpPutObjAux(prefix, URL, parameters, data) {
188
- let config = {
189
- method: 'put',
190
- url: URL,
191
- baseURL: prefix
192
- };
193
-
194
- this._setAuthHeader(config);
195
-
196
- if (parameters !== undefined) {
197
- config['params'] = parameters;
198
- }
199
-
200
- config.data = data;
201
- return new Promise(function (resolve, reject) {
202
- axios(config).then((response) => {
203
- if (response.status >= 200 && response.status <= 299) {
204
- return resolve(response.data);
205
- }
206
- return reject(response);
207
- },
208
- (response) => {
209
- return reject(response);
210
- }
211
- );
212
- });
213
- }
214
-
215
- _httpPutObj(URL,parameters, data) {
216
- return this._httpPutObjAux(this.host,URL, parameters, data);
217
- }
218
-
219
- _httpPutV3Obj(URL,parameters,data) {
220
- return this._httpPutObjAux(this._v3baseURL,URL,parameters,data);
221
- }
222
-
223
-
224
- _httpDeleteObj(URL, parameters, data) {
225
- return this._httpDeleteObjAux(this.host,URL,parameters, data);
226
- }
227
-
228
- _httpDeleteV3Obj(URL, parameters) {
229
- return this._httpDeleteObjAux(this._v3baseURL, URL, parameters, undefined);
230
- }
231
-
232
- _httpDeleteObjAux(prefix, URL, parameters, data) {
233
- let config = {
234
- method: 'delete',
235
- url: URL,
236
- baseURL: prefix
237
- };
238
-
239
- this._setAuthHeader(config);
240
-
241
- if (parameters !== undefined) {
242
- config['params'] = parameters;
243
- }
244
-
245
- if (data !== undefined) {
246
- config['data'] = data;
247
- }
248
-
249
- return new Promise(function (resolve, reject) {
250
- axios(config).then((response) => {
251
- if (response.status >= 200 && response.status <= 299) {
252
- return resolve(response.data);
253
- }
254
- return reject(response);
255
- },
256
- (response) => {
257
- return reject(response);
258
- }
259
- );
260
- });
261
-
262
- }
263
-
264
- /* admin functions */
265
-
266
- getStatus() {
267
- return this._httpGetOpenObj('admin/status');
268
- }
269
-
270
- /* user functions */
271
-
272
- getSignedInUser() {
273
- if (this._authType == null) {
274
- throw new Error('Authentication parameters are missing in NDEx client.');
275
- }
276
- return this._httpGetProtectedObj('user', {valid: true});
277
- }
278
-
279
- getUser(uuid) {
280
- return this._httpGetProtectedObj('user/' + uuid);
281
- }
282
-
283
- getAccountPageNetworks(offset, limit) {
284
- return new Promise((resolve, reject) => {
285
- this.getSignedInUser().then((user) => {
286
- let params = {};
287
-
288
- if (offset !== undefined) {
289
- params.offset = offset;
290
- }
291
- if (limit !== undefined) {
292
- params.limit = limit;
293
- }
294
- this._httpGetProtectedObj('/user/' + user.externalId + '/networksummary', params).then(
295
- (networkArray) => {resolve(networkArray);}, (err) => {reject(err);}
296
- );
297
- }, (err) => {reject(err);});
298
-
299
- });
300
- }
301
-
302
- getAccountPageNetworksByUUID(uuid, offset, limit) {
303
- let params = {};
304
-
305
- if (offset !== undefined) {
306
- params.offset = offset;
307
- }
308
- if (limit !== undefined) {
309
- params.limit = limit;
310
- }
311
- return this._httpGetProtectedObj('user/' + uuid + '/networksummary', params);
312
- }
313
-
314
- /* group functions */
315
-
316
- // return the UUID of the created group to the resolver
317
- createGroup(group) {
318
- return new Promise((resolve, reject)=> {
319
- this._httpPostProtectedObj('group', undefined, group).then(
320
- (response) => {
321
- let uuidr = response.split('/');
322
-
323
- let uuid = uuidr[uuidr.length - 1];
324
-
325
- return resolve(uuid);
326
- },
327
- (err) => {reject(err);}
328
- );
329
- });
330
- }
331
-
332
- getGroup(uuid) {
333
- return this._httpGetProtectedObj('group/' + uuid);
334
- }
335
-
336
- updateGroup(group) {
337
- return new Promise((resolve, reject)=> {
338
- this._httpPutObj('group/' + group.externalId, undefined, group).then(
339
- (response) => {
340
- return resolve(response);
341
- },
342
- (err) => {reject(err);}
343
- );
344
- });
345
- }
346
-
347
- deleteGroup(uuid) {
348
- return this._httpDeleteObj('group/' + uuid);
349
- }
350
-
351
- /* network functions */
352
-
353
- getRawNetwork(uuid, accessKey) {
354
-
355
- let parameters = {};
356
-
357
- if (accessKey !== undefined) {
358
- parameters = {accesskey: accessKey};
359
- }
360
-
361
- return this._httpGetProtectedObj('network/' + uuid, parameters);
362
-
363
- }
364
-
365
- getCX2Network(uuid, accessKey) {
366
-
367
- let parameters = {};
368
-
369
- if (accessKey !== undefined) {
370
- parameters = {accesskey: accessKey};
371
- }
372
-
373
- return this._httpGetV3ProtectedObj('networks/' + uuid, parameters);
374
-
375
- }
376
-
377
- getNetworkSummary(uuid, accessKey) {
378
- let parameters = {};
379
-
380
- if (accessKey !== undefined) {
381
- parameters = {accesskey: accessKey};
382
- }
383
-
384
- return this._httpGetProtectedObj('network/' + uuid + '/summary', parameters);
385
- }
386
-
387
- getNetworkV3Summary(uuid, accessKey,fmt) {
388
- let parameters = {format: fmt != null? fmt : "FULL"}
389
-
390
- if (accessKey != null) {
391
- parameters ['accesskey'] = accessKey;
392
- }
393
-
394
- return this._httpGetV3ProtectedObj('networks/' + uuid + '/summary', parameters);
395
- }
396
-
397
- getNetworkDOI(uuid, key, email){
398
- return this._httpGetV3ProtectedObj('networks/' + uuid + '/DOI', {key: key, email: email});
399
- }
400
-
401
- getAttributesOfSelectedNodes(uuid, {ids: nodeIds, attributeNames: names},accessKey) {
402
- let parameters = {
403
- };
404
-
405
- if (accessKey != null) {
406
- parameters ['accesskey'] = accessKey;
407
- }
408
-
409
- let data = {
410
- "ids": nodeIds,
411
- "attributeNames": names,
412
- };
413
-
414
- return this._httpPostV3ProtectedObj('/search/networks/' + uuid + '/nodes', parameters, data);
415
- }
416
-
417
- createNetworkFromRawCX(rawCX, parameters) {
418
- return new Promise((resolve, reject) =>{
419
- this._httpPostProtectedObj('network', parameters, rawCX).then(
420
- (response) => {
421
- let uuidr = response.split('/');
422
-
423
- let uuid = uuidr[uuidr.length - 1];
424
-
425
- return resolve(uuid);
426
- },
427
- (err) => {reject(err);}
428
- );
429
- });
430
- }
431
-
432
- copyNetwork(uuid){
433
- return this._httpPostV3ProtectedObj('networks/'+uuid+'/copy', undefined, {});
434
- }
435
-
436
- updateNetworkFromRawCX(uuid, rawcx) {
437
- return this._httpPutObj('network/' + uuid, undefined, rawcx);
438
- }
439
-
440
- deleteNetwork(uuid) {
441
- return this._httpDeleteObj('network/' + uuid);
442
- }
443
-
444
- /* task functions */
445
-
446
- /* search functions */
447
- searchUsers(searchTerms, start, size) {
448
- let params = {};
449
-
450
- if (start !== undefined) {
451
- params.start = start;
452
- }
453
- if (size !== undefined) {
454
- params.limit = size;
455
- }
456
- let data = {searchString: searchTerms};
457
-
458
- return this._httpPostProtectedObj('search/user', params, data);
459
-
460
- }
461
-
462
- searchGroups(searchTerms, start, size) {
463
- let params = {};
464
-
465
- if (start !== undefined) {
466
- params.start = start;
467
- }
468
- if (size !== undefined) {
469
- params.limit = size;
470
- }
471
- let data = {searchString: searchTerms};
472
-
473
- return this._httpPostProtectedObj('search/group', params, data);
474
-
475
- }
476
-
477
- searchNetworks(searchTerms, start, size, optionalParameters) {
478
- let params = {};
479
-
480
- if (start !== undefined) {
481
- params.start = start;
482
- }
483
- if (size !== undefined) {
484
- params.limit = size;
485
- }
486
-
487
- let data = {searchString: searchTerms};
488
-
489
- if (optionalParameters !== undefined) {
490
- if (optionalParameters.permission !== undefined) {
491
- data.permission = optionalParameters.permission;
492
- }
493
- if (optionalParameters.includeGroups !== undefined) {
494
- data.includeGroups = optionalParameters.includeGroups;
495
- }
496
- if (optionalParameters.accountName !== undefined) {
497
- data.accountName = optionalParameters.accountName;
498
- }
499
- }
500
-
501
- return this._httpPostProtectedObj('search/network', params, data);
502
- }
503
-
504
- neighborhoodQuery(uuid, searchTerms, saveResult, parameters, outputCX2 = false) {
505
- let params = {};
506
-
507
- if (saveResult !== undefined && saveResult === true) {params.save = true;}
508
-
509
- let data = {searchString: searchTerms,
510
- searchDepth: 1};
511
-
512
- if (parameters !== undefined) {
513
- if (parameters.searchDepth !== undefined) {
514
- data.searchDepth = parameters.searchDepth;
515
- }
516
- if (parameters.edgeLimit !== undefined) {
517
- data.edgeLimit = parameters.edgeLimit;
518
- }
519
- if (parameters.errorWhenLimitIsOver !== undefined) {
520
- data.errorWhenLimitIsOver = parameters.errorWhenLimitIsOver;
521
- }
522
- if (parameters.directOnly !== undefined) {
523
- data.directOnly = parameters.directOnly;
524
- }
525
- if ( parameters.nodeIds !=null) {
526
- data.nodeIds = parameters.nodeIds;
527
- }
528
- }
529
- if( outputCX2)
530
- return this._httpPostV3ProtectedObj('search/network/' + uuid + '/query', params, data);
531
-
532
- return this._httpPostProtectedObj('search/network/' + uuid + '/query', params, data);
533
-
534
- }
535
-
536
- interConnectQuery(uuid, searchTerms, saveResult, parameters, outputCX2 = false) {
537
- let params = {};
538
-
539
- if (saveResult !== undefined && saveResult === true) {params.save = true;}
540
-
541
- let data = {searchString: searchTerms};
542
-
543
- if (parameters !== undefined) {
544
- if (parameters.edgeLimit !== undefined) {
545
- data.edgeLimit = parameters.edgeLimit;
546
- }
547
- if (parameters.errorWhenLimitIsOver !== undefined) {
548
- data.errorWhenLimitIsOver = parameters.errorWhenLimitIsOver;
549
- }
550
- if ( parameters.nodeIds !=null) {
551
- data.nodeIds = parameters.nodeIds;
552
- }
553
- }
554
- if (outputCX2)
555
- return this._httpPostV3ProtectedObj('search/networks/' + uuid + '/interconnectquery', params, data);
556
-
557
- return this._httpPostProtectedObj('search/network/' + uuid + '/interconnectquery', params, data);
558
-
559
- }
560
-
561
- /* batch functions */
562
- getUsersByUUIDs(uuidList) {
563
- return this._httpPostProtectedObj('batch/user', undefined, uuidList);
564
- }
565
-
566
- getGroupsByUUIDs(uuidList) {
567
- return this._httpPostProtectedObj('batch/group', undefined, uuidList);
568
- }
569
-
570
- getNetworkSummariesByUUIDs(uuidList, accessKey) {
571
- let parameter = accessKey === undefined ? undefined :
572
- {accesskey: accessKey};
573
-
574
- return this._httpPostProtectedObj('batch/network/summary', parameter, uuidList);
575
- }
576
-
577
- getNetworkSummariesV3ByUUIDs(uuidList, accessKey,fmt) {
578
- let parameter = {format: fmt == undefined ? "FULL" : fmt}
579
-
580
- if(accessKey != null)
581
- parameter['accesskey']= accessKey;
582
-
583
- return this._httpPostV3ProtectedObj('batch/networks/summary', parameter, uuidList);
584
- }
585
-
586
-
587
- getNetworkPermissionsByUUIDs(uuidList) {
588
- return this._httpPostProtectedObj('batch/network/permission', undefined, uuidList);
589
- }
590
-
591
- exportNetworks(exportJob) {
592
- return this._httpPostProtectedObj('batch/network/export', undefined, exportJob);
593
- }
594
-
595
- moveNetworks(networkIds, folderId){
596
- if(Object.isArray(networkIds)){
597
- return this._httpPostV3ProtectedObj('batch/networks/move', undefined, {targetFolder:folderId, networks: networkIds});
598
- }else{
599
- throw new Error('Invalid networkIds');
600
- }
601
- }
602
-
603
- setNetworksVisibility(files, visibility){
604
- if(this._validateShareData(files)){
605
- return this._httpPostV3ProtectedObj('batch/networks/visibility', undefined, {items: files, visibility: visibility});
606
- }else{
607
- throw new Error('Invalid share data');
608
- }
609
- }
610
-
611
- /* network set functions */
612
- createNetworkSet({name, description}){
613
- return new Promise((resolve, reject)=> {
614
- this._httpPostProtectedObj('networkset', undefined, {name, description}).then(
615
- (response) => {
616
- let uuidr = response.split('/');
617
-
618
- let uuid = uuidr[uuidr.length - 1];
619
-
620
- return resolve(uuid);
621
- },
622
- (err) => {reject(err);}
623
- );
624
- });
625
- }
626
-
627
- updateNetworkSet(uuid, {name, description}){
628
- return new Promise((resolve, reject)=> {
629
- this._httpPutObj('networkset/' + uuid, undefined, {uuid, name, description}).then(
630
- (response) => {
631
- return resolve(response);
632
- },
633
- (err) => {reject(err);}
634
- );
635
- });
636
- }
637
-
638
- deleteNetworkSet(uuid){
639
- return this._httpDeleteObj('networkset/' + uuid);
640
- }
641
-
642
- getNetworkSet(uuid, accessKey){
643
- let parameters = {};
644
-
645
- if (accessKey !== undefined) {
646
- parameters = {accesskey: accessKey};
647
- }
648
-
649
- return this._httpGetProtectedObj('networkset/' + uuid, parameters);
650
- }
651
-
652
- addToNetworkSet(networkSetUUID, networkUUIDs){
653
- return this._httpPostProtectedObj('networkset/' + networkSetUUID + '/members', undefined, networkUUIDs);
654
- }
655
-
656
- deleteFromNetworkSet(networkSetUUID, networkUUIDS){
657
- return this._httpDeleteObj('networkset/' + networkSetUUID + '/members', undefined, networkUUIDS);
658
- }
659
-
660
- updateNetworkSetSystemProperty(networksetUUID, data){
661
- return this._httpPutObj('networkset/' + networksetUUID + '/systemproperty', undefined, data);
662
- }
663
-
664
-
665
- /* undocumented functions. Might be changed ... */
666
-
667
- // layout update is a list of objects:
668
- // [{ node: 1, x: 100, y: 100}, {node: 2, x: 1003, y: 200 }...]
669
- updateCartesianLayoutAspect(uuid, nodePositions){
670
-
671
- // 1. get node coordinates from cy.js model in the format of cartesian aspect
672
- // 2. generate CX for the put request
673
- // 3. example
674
- // [{
675
- // "numberVerification": [
676
- // {
677
- // "longNumber": 283213721732712
678
- // }
679
- // ]
680
- // }, {
681
- // "metaData": [{
682
- // "name": "cartesianLayout", "elementCount": 100 // num nodes here
683
- // }],
684
- // "cartesianLayout": [{
685
- // "node": 100, "x": 23213.12, "y": 3234.5
686
- // }]
687
- // }]
688
- const cartesianLayoutUpdate = [
689
- CX1_HEADER,
690
- {
691
- metaData: [{
692
- name: 'cartesianLayout',
693
- elementCount: nodePositions.length
694
- }]
695
- },
696
- {
697
- cartesianLayout: nodePositions
698
- },
699
- {
700
- status: [{
701
- error: '',
702
- success: true
703
- }]
704
- }
705
- ]
706
-
707
- return this._httpPutObj(`network/${uuid}/aspects`, undefined, cartesianLayoutUpdate);
708
- }
709
-
710
- // new v3 functions
711
- getRandomEdges(uuid, limit, accessKey ) {
712
-
713
- if ( limit <=0)
714
- throw new Error("Value of parameter limit has to be greater than 0.");
715
-
716
- let parameters = {
717
- size: limit,
718
- method: "random"
719
- };
720
-
721
- if (accessKey !== undefined) {
722
- parameters = {accesskey: accessKey};
723
- }
724
-
725
- return this._httpGetV3ProtectedObj('networks/' + uuid + '/aspects/edges', parameters);
726
- }
727
-
728
- getMetaData(uuid, accessKey) {
729
- let parameters = {
730
- };
731
-
732
- if (accessKey !== undefined) {
733
- parameters ['accesskey'] =accessKey;
734
- }
735
-
736
- return this._httpGetProtectedObj('network/' + uuid + '/aspect', parameters);
737
- }
738
-
739
- getAspectElements(uuid, aspectName, limit, accessKey ) {
740
-
741
- let parameters = {
742
- };
743
-
744
- if ( limit !== undefined) {
745
- parameters = {
746
- size: limit
747
- };
748
- }
749
-
750
- if (accessKey !== undefined) {
751
- parameters ['accesskey'] =accessKey;
752
- }
753
-
754
- return this._httpGetV3ProtectedObj('networks/' + uuid + '/aspects/' + aspectName, parameters);
755
- }
756
-
757
- getFilteredEdges(uuid, columnName, valueString, operator, limit, order, format, accessKey ) {
758
-
759
- let parameters = {
760
- };
761
-
762
-
763
- if ( limit !== undefined) {
764
- parameters = {
765
- size: limit
766
- };
767
- }
768
-
769
- if ( order !== undefined) {
770
- parameters['order'] = order;
771
- }
772
-
773
- if (accessKey !== undefined) {
774
- parameters ['accesskey'] = accessKey;
775
- }
776
-
777
- if ( format !== undefined ) {
778
- parameters['format'] = format;
779
- }
780
-
781
- let data = {
782
- "name": columnName,
783
- "value": valueString,
784
- "operator": operator
785
- };
786
-
787
- return this._httpPostV3ProtectedObj('/search/networks/' + uuid + '/edges', parameters, data);
788
- }
789
-
790
- getCX2MetaData(uuid, accessKey ) {
791
-
792
- let parameters = {
793
- };
794
-
795
- if (accessKey !== undefined) {
796
- parameters ['accesskey'] =accessKey;
797
- }
798
-
799
- return this._httpGetV3ProtectedObj('networks/' + uuid + '/aspects', parameters);
800
- }
801
-
802
- cancelDOIRequest(uuid) {
803
- const cancelBody =
804
- {type: "Cancel_DOI", networkId: uuid}
805
- ;
806
-
807
- return this._httpPostProtectedObj('admin/request', {}, cancelBody);
808
- }
809
-
810
-
811
- // unstable function to upload CX2 to NDEx
812
- createNetworkFromRawCX2(rawCX2, makePublic = false) {
813
- let config = {
814
- method: 'post',
815
- url: 'networks',
816
- baseURL: this._v3baseURL,
817
- params: {
818
- visibility: makePublic ? 'PUBLIC' : 'PRIVATE'
819
- }
820
- };
821
-
822
- this._setAuthHeader(config);
823
- config.data = rawCX2;
824
-
825
- return axios(config).then(res => {
826
- let { location } = res.headers;
827
- let uuid = location.split('/').pop();
828
-
829
- return { uuid };
830
- });
831
- }
832
-
833
- updateNetworkFromRawCX2(uuid, rawCX2) {
834
- return this._httpPutV3Obj('networks/'+uuid, undefined, rawCX2);
835
- }
836
-
837
- createCyWebWorkspace(workspace) {
838
- return new Promise((resolve, reject)=> {
839
- this._httpPostV3ProtectedObj('workspaces', undefined, workspace).then(
840
- (response) => {
841
- // let uuidr = response.split('/');
842
-
843
- // let uuid = uuidr[uuidr.length - 1];
844
-
845
- return resolve(response);
846
- },
847
- (err) => {reject(err);}
848
- );
849
- });
850
-
851
- }
852
-
853
- getCyWebWorkspace(workspaceId) {
854
- return this._httpGetV3ProtectedObj('workspaces/'+ workspaceId, {});
855
- }
856
-
857
- deleteCyWebWorkspace(workspaceId) {
858
- return this._httpDeleteV3Obj('workspaces/'+ workspaceId, undefined);
859
- }
860
-
861
- updateCyWebWorkspace(workspaceId, workspaceObj) {
862
- return this._httpPutV3Obj('workspaces/'+workspaceId, undefined, workspaceObj);
863
- }
864
-
865
- updateCyWebWorkspaceName(workspaceId, newName) {
866
- return this._httpPutV3Obj('workspaces/'+workspaceId+'/name', undefined, {'name': newName});
867
- }
868
-
869
- updateCyWebWorkspaceNetworks(workspaceId, networkIds) {
870
- return this._httpPutV3Obj('workspaces/'+workspaceId+'/networkids', undefined, networkIds);
871
- }
872
-
873
- getUserCyWebWorkspaces() {
874
- return new Promise((resolve, reject) => {
875
- this.getSignedInUser().then((user) => {
876
- this._httpGetV3ProtectedObj('users/'+ user.externalId + '/workspaces', {}).then(
877
- (workspaceArray) => {resolve(workspaceArray);}, (err) => {reject(err);}
878
- );
879
- }, (err) => {reject(err);});
880
-
881
- });
882
- }
883
-
884
- signInFromIdToken(idToken) {
885
- return this._httpPostV3ProtectedObj('users/signin', undefined, {idToken: idToken});
886
- }
887
-
888
- // Permission and AccessKey APIs
889
-
890
- //Todo:permission APIs
891
-
892
- getAccessKey(uuid){
893
- return this._httpGetProtectedObj('networks/'+uuid+'/accesskey', {});
894
- }
895
-
896
- updateAccessKey(uuid, action){
897
- return this._httpPutObj('networks/'+uuid+'/accesskey', {action: action});
898
- }
899
-
900
- // V3-Files APIs
901
- copyFile(fromUuid, toPath, type, accessKey) {
902
- let parameters = {};
903
-
904
- if (accessKey !== undefined) {
905
- parameters ['accesskey'] = accessKey;
906
- }
907
- return this._httpPostV3ProtectedObj('files/copy', parameters, {from_uuid: fromUuid, type: type, to_path: toPath,});
908
- }
909
-
910
- getCount() {
911
- return this._httpGetV3ProtectedObj('files/count', {});
912
- }
913
-
914
- getTrash(){
915
- return this._httpGetV3ProtectedObj('files/trash', {});
916
- }
917
-
918
- emptyTrash() {
919
- return this._httpDeleteV3Obj('files/trash', undefined);
920
- }
921
-
922
- permanentlyDeleteFile(fileId) {
923
- return this._httpDeleteV3Obj('files/trash/'+fileId, undefined);
924
- }
925
-
926
- restoreFile(networkIds, folderIds, shortcutIds) {
927
- return this._httpPostV3ProtectedObj('files/trash/restore', undefined, {networks: networkIds, folders: folderIds, shortcuts: shortcutIds});
928
- }
929
- // Sharing
930
- //add, remove, update member
931
- _validateShareData(data) {
932
- // Check if data is an object and has files property
933
- if (typeof data !== 'object' || data === null || data.files === undefined) {
934
- throw new Error('Data must be an object with a "files" property');
935
- }
936
-
937
- // Check if files is an object
938
- if (typeof data.files !== 'object' || data.files === null) {
939
- throw new Error('The "files" property must be an object');
940
- }
941
-
942
- // Check each key-value pair in files
943
- const validValues = ['NETWORK', 'FOLDER', 'SHORTCUT'];
944
-
945
- for (const [uuid, fileType] of Object.entries(data.files)) {
946
- // Validate UUID format (basic validation)
947
- if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(uuid)) {
948
- throw new Error(`Invalid UUID format: ${uuid}`);
949
- }
950
-
951
- // Validate file type
952
- if (!validValues.includes(fileType)) {
953
- throw new Error(`Invalid file type for ${uuid}: ${fileType}. Must be one of: ${validValues.join(', ')}`);
954
- }
955
- }
956
- }
957
- _validateMemberData(data){
958
- if(typeof data !== 'object' || data === null || data.members === undefined){
959
- throw new Error('Data must be an object with a "members" property');
960
- }
961
- const validValues = ['READ', 'WRITE'];
962
- for (const [uuid, permission] of Object.entries(data.members)) {
963
- if (!validValues.includes(permission)) {
964
- throw new Error(`Invalid permission for ${uuid}: ${permission}. Must be one of: ${validValues.join(', ')}`);
965
- }
966
- if(typeof uuid !== 'string' || !/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(uuid)){
967
- throw new Error(`Invalid UUID format: ${uuid}`);
968
- }
969
- }
970
-
971
- }
972
-
973
- updateMember(files, members){
974
- if(this._validateShareData(files) && this._validateMemberData(members)){
975
- return this._httpPostV3ProtectedObj('files/sharing/members', undefined, {files: files, members: members});
976
- }else{
977
- throw new Error('Invalid share data');
978
- }
979
- }
980
-
981
- listMembers(files){
982
- return this._httpGetV3ProtectedObj('files/sharing/members/list', files);
983
- }
984
-
985
-
986
-
987
- transferOwnership(files, newOwner){
988
- if(this._validateShareData(files)){
989
- return this._httpPostV3ProtectedObj('files/sharing/transfer_ownership', undefined, {files: files, new_owner: newOwner});
990
- } else {
991
- throw new Error('Invalid share data');
992
- }
993
- }
994
-
995
- listShares(limit){
996
- let parameters = {};
997
- if(limit !== undefined){
998
- parameters['limit'] = limit;
999
- }
1000
- return this._httpPostV3ProtectedObj('files/sharing/list', parameters);
1001
- }
1002
-
1003
- share(files){
1004
- if(this._validateShareData(files)){
1005
- return this._httpPostV3ProtectedObj('files/sharing/share', undefined, {files: files});
1006
- }else{
1007
- throw new Error('Invalid share data');
1008
- }
1009
- }
1010
-
1011
- unshare(files){
1012
- if(this._validateShareData(files)){
1013
- return this._httpPostV3ProtectedObj('files/sharing/unshare', undefined, {files: files});
1014
- }else{
1015
- throw new Error('Invalid share data');
1016
- }
1017
- }
1018
-
1019
- // Folder
1020
- getFolders(limit){
1021
- let parameters = {};
1022
-
1023
- if (limit !== undefined) {
1024
- parameters ['limit'] = limit;
1025
- }
1026
- return this._httpGetV3ProtectedObj('files/folders', parameters);
1027
- }
1028
-
1029
- createFolder(name, parentFolderId) {
1030
- return this._httpPostV3ProtectedObj('files/folders', undefined, {name: name, parent: parentFolderId});
1031
- }
1032
-
1033
- getFolder(folderId, accessKey) {
1034
- let parameters = {};
1035
-
1036
- if (accessKey !== undefined) {
1037
- parameters ['accesskey'] = accessKey;
1038
- }
1039
- return this._httpGetV3ProtectedObj('files/folders/' + folderId, parameters);
1040
- }
1041
-
1042
- updateFolder(folderId, name, parentFolderId) {
1043
- return this._httpPutV3Obj('files/folders/' + folderId, undefined, {name: name, parent: parentFolderId});
1044
- }
1045
-
1046
- deleteFolder(folderId) {
1047
- return this._httpDeleteV3Obj('files/folders/' + folderId, undefined);
1048
- }
1049
-
1050
- getFolderCount(folderId, accessKey) {
1051
- let parameters = {};
1052
-
1053
- if (accessKey !== undefined) {
1054
- parameters ['accesskey'] = accessKey;
1055
- }
1056
- return this._httpGetV3ProtectedObj('files/folders/' + folderId + '/count', parameters);
1057
- }
1058
-
1059
- getFolderList(folderId, accessKey, format, type) {
1060
- let parameters = {};
1061
-
1062
- if (accessKey !== undefined) {
1063
- parameters ['accesskey'] = accessKey;
1064
- }
1065
- if (format !== undefined) {
1066
- parameters['format'] = format;
1067
- }
1068
- if (type !== undefined) {
1069
- parameters['type'] = type;
1070
- }
1071
- return this._httpGetV3ProtectedObj('files/folders/' + folderId + '/list', parameters);
1072
- }
1073
-
1074
- // Sortcut
1075
- getShortcuts(limit){
1076
- let parameters = {};
1077
-
1078
- if (limit !== undefined) {
1079
- parameters ['limit'] = limit;
1080
- }
1081
- return this._httpGetV3ProtectedObj('files/shortcuts', parameters);
1082
- }
1083
-
1084
- createShortcut(name, parentFolderId, targetId, tagetType) {
1085
- return this._httpPostV3ProtectedObj('files/shortcuts', undefined, {name: name, parent: parentFolderId, target: targetId, targetType: tagetType});
1086
- }
1087
-
1088
- getShortcut(shortcutId, accessKey) {
1089
- let parameters = {};
1090
-
1091
- if (accessKey !== undefined) {
1092
- parameters ['accesskey'] = accessKey;
1093
- }
1094
- return this._httpGetV3ProtectedObj('files/shortcuts/' + shortcutId, parameters);
1095
- }
1096
-
1097
- updateShortcut(shortcutId, name, parentFolderId, targetId, tagetType) {
1098
- return this._httpPutV3Obj('files/shortcuts/' + shortcutId, undefined, {name: name, parent: parentFolderId, target: targetId, targetType: tagetType});
1099
- }
1100
-
1101
- delteShortcut(shortcutId) {
1102
- return this._httpDeleteV3Obj('files/shortcuts/' + shortcutId, undefined);
1103
- }
1104
-
1105
- }
1106
-
1107
- export default NDEx;