-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbundle.js
9091 lines (8541 loc) · 308 KB
/
bundle.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
require = (function () {
function r (e, n, t) {
function o (i, f) {
if (!n[i]) {
if (!e[i]) {
const c = typeof require === 'function' && require
if (!f && c) return c(i, !0)
if (u) return u(i, !0)
const a = new Error("Cannot find module '" + i + "'")
throw ((a.code = 'MODULE_NOT_FOUND'), a)
}
const p = (n[i] = { exports: {} })
e[i][0].call(
p.exports,
function (r) {
const n = e[i][1][r]
return o(n || r)
},
p,
p.exports,
r,
e,
n,
t
)
}
return n[i].exports
}
for (
var u = typeof require === 'function' && require, i = 0;
i < t.length;
i++
) { o(t[i]) }
return o
}
return r
})()(
{
1: [
function (require, module, exports) {
'use strict'
const _axios = _interopRequireDefault(require('axios'))
function _interopRequireDefault (obj) {
return obj?.__esModule ? obj : { default: obj }
}
class Bootstrap {
// Bootstraps API Client
/**
* @class Bootstrap
* Bootstrap is used to manage bootstrap configurations.
* It is used to create, update, view and remove bootstrap configurations.
* It is also used to bootstrap a thing.
* @param {string} bootstraps_url - The url of the bootstraps service.
* @param {string} content_type - The content type of the request.
* @param {string} bootstrapsEndpoint - The endpoint of the bootstraps service which is
* configs.
* @returns {Bootstrap} - Returns a Bootstrap object.
*
*/
constructor (bootstraps_url) {
this.bootstraps_url = bootstraps_url
this.content_type = 'application/json'
this.bootstrapsEndpoint = 'configs'
}
Create (config, token) {
// Create a bootstrap configuration
/**
* @method Create - Create a new bootstrap configuration.
* Some of the key data needed include the external_key and external_id which must be
* specific to the thing provided with the thing_id. Mind that every configuration
* must have a specific thing_id.
* @param {object} config - The configuration object.
* @param {string} token - The token to be used for authentication.
* @example
* const config = {
* "external_id": "345",
* "external_key": "012",
* "thing_id": "3d49a42f-63fd-491b-9784-adf4b64ef347",
* "name": "thing_name"
* }
*/
const options = {
method: 'post',
maxBodyLength: Infinity,
url: `${this.bootstraps_url}/things/${this.bootstrapsEndpoint}`,
headers: {
'Content-Type': this.content_type,
Authorization: `Bearer ${token}`
},
data: JSON.stringify(config)
}
return _axios.default
.request(options)
.then((_response) => {
return 'Configuration added'
})
.catch((error) => {
return error.response.data
})
}
Whitelist (config, token) {
// Update a bootstrap configuration
/**
* @method Whitelist - Allows a logged in user to update a bootstrap configuration.
* This changes the status of the config to whitelisted.
* @param {object} config - The configuration object.
* @param {string} token - The token to be used for authentication.
* @example
* const config = {
* "external_id": "345",
* "external_key": "012",
* "thing_id": "3d49a42f-63fd-491b-9784-adf4b64ef347",
* "name": "thing_name"
* }
*/
const options = {
method: 'put',
maxBodyLength: Infinity,
url: `${this.bootstraps_url}/things/state/${config.thing_id}`,
headers: {
'Content-Type': this.content_type,
Authorization: `Bearer ${token}`
},
data: JSON.stringify(config)
}
return _axios.default
.request(options)
.then((_response) => {
return 'Configuration updated'
})
.catch((error) => {
return error.response.data
})
}
Update (config, token) {
// Update a bootstrap configuration
/**
* @method Update - Allows a logged in user to update a bootstrap configuration.
* This can change the name of the config and metadata.
* @param {object} config - The configuration object.
* @param {string} token - The token to be used for authentication.
* @example
* const config = {
* "external_id": "345",
* "external_key": "012",
* "thing_id": "3d49a42f-63fd-491b-9784-adf4b64ef347",
* "name": "thing_name"
* }
*/
const options = {
method: 'put',
maxBodyLength: Infinity,
url: `${this.bootstraps_url}/things/configs/${config.thing_id}`,
headers: {
'Content-Type': this.content_type,
Authorization: `Bearer ${token}`
},
data: JSON.stringify(config)
}
return _axios.default
.request(options)
.then((_response) => {
return 'Configuration updated'
})
.catch((error) => {
return error.response.data
})
}
View (thing_id, token) {
// View a bootstrap configuration
/**
* @method View - Allows a logged in user to view a bootstrap configuration.
* Once provided with the thing_id and a valid token, it returns the configuration object.
* @param {string} thing_id - The thing_id of the configuration to be viewed.
* @param {string} token - The token to be used for authentication.
*/
const options = {
method: 'get',
maxBodyLength: Infinity,
url: `${this.bootstraps_url}/things/${this.bootstrapsEndpoint}/${thing_id}`,
headers: {
'Content-Type': this.content_type,
Authorization: `Bearer ${token}`
}
}
return _axios.default
.request(options)
.then((response) => {
return response.data
})
.catch((error) => {
return error.response.data
})
}
UpdateCerts (config_id, client_cert, client_key, ca, token) {
// Update certs of a bootstrap configuration
/**
* @method UpdateCerts - Allows a logged in user to update the certs of a bootstrap configuration.
* Update is performed by replacing the current certificate data with values provided in a request payload.
* @param {string} config_id - The config_id of the configuration to be updated. This can also mean the thing_id.
* @param {string} client_cert - The client certificate to be used.
* @param {string} client_key - The client key to be used.
* @param {string} ca - The certificate authority to be used.
* @param {string} token - The token to be used for authentication.
*
*/
const payload = {
client_cert,
client_key,
ca_cert: ca
}
const options = {
method: 'patch',
maxBodyLength: Infinity,
url: `${this.bootstraps_url}/configs/certs/${config_id}`,
headers: {
'Content-Type': this.content_type,
Authorization: `Bearer ${token}`
},
data: JSON.stringify(payload)
}
return _axios.default
.request(options)
.then((response) => {
return response.data
})
.catch((error) => {
return error.response.data
})
}
Remove (config_id, token) {
// Remove a bootstrap configuration
/**
* @method Remove - Allows a logged in user to delete a bootstrap configuration.
* @param {string} config_id - The config_id of the configuration to be deleted.
* This can also mean the thing_id.
* @param {string} token - The token to be used for authentication.
*
*/
const options = {
method: 'delete',
maxBodyLength: Infinity,
url: `${this.bootstraps_url}/things/${this.bootstrapsEndpoint}/${config_id}`,
headers: {
'Content-Type': this.content_type,
Authorization: `Bearer ${token}`
}
}
return _axios.default
.request(options)
.then((_response) => {
return 'Configuration removed'
})
.catch((error) => {
return error.response.data
})
}
Bootstrap (external_id, external_key) {
// Retrive a bootstrap configuration
/**
* @method Bootstrap - Retrieves a configuration with given external ID and encrypted external key.
* @param {string} external_id - The external ID of the configuration to be retrieved.
* @param {string} external_key - The encrypted external key of the configuration to be retrieved.
* @return {object} - Returns a config object.
*/
const options = {
method: 'get',
maxBodyLength: Infinity,
url: `${this.bootstraps_url}/things/bootstrap/${external_id}`,
headers: {
'Content-Type': this.content_type,
Authorization: `Thing ${external_key}`
}
}
return _axios.default
.request(options)
.then((response) => {
return response.data
})
.catch((error) => {
return error.response.data
})
}
}
module.exports = Bootstrap
},
{ axios: 8 }
],
2: [
function (require, module, exports) {
'use strict'
const _axios = _interopRequireDefault(require('axios'))
function _interopRequireDefault (obj) {
return obj?.__esModule ? obj : { default: obj }
}
// import Errors from "./errors.js";
class Certs {
// Certs API Client
/**
*@class Certs - Certs is used to manage certificates.
*It is used to issue, view and revoke certificates.
* @param {string} certs_url - The url of the certs service.
* @param {string} content_type - The content type of the request.
* @param {string} certsEndpoint - The endpoint of the certs service which is certs.
* @returns {Certs} - Returns a Certs object.
*/
constructor (certs_url) {
this.certs_url = certs_url
this.content_type = 'application/json'
this.certsEndpoint = 'certs'
}
Issue (thing_id, valid, token) {
// Issue a certificate
/**
* @method Issue - Issue a certificate to a thing.
* Requires a thing_id and a valid time in hours as well as a token.
* @param {string} thing_id - The thing_id of the thing to be issued a certificate.
* @param {number} valid - The time in hours for which the certificate is valid.
* @example
* const certs = {
* "cert_serial": "22:16:df:60:c2:99:bc:c4:9b:1d:fd:71:5e:e9:07:d9:1b:3c:85:1d",
* "client_cert": "-----BEGIN CERTIFICATE-----\nMIIEATCCAumgAwIBAgIUIhbfYMKZvMSbHf1xXukH2Rs8hR0wDQYJKoZIhvcNAQEL1k\n-----END CERTIFICATE-----",
* "client_key": "-----BEGIN RSA PRIVATE KEY-----\nMIIEoQIBAAKCAQEAy9gF84a5s6jlX6hkAPXrLYqvdhe6uygdr6eHfd5erdcdxfgc\n-----END RSA PRIVATE KEY-----",
* "expiration": "2023-09-20T10:02:48Z",
* "thing_id": "3d49a42f-63fd-491b-9784-adf4b64ef347"
* }
*/
const payload = {
thing_id,
ttl: valid
}
const options = {
method: 'post',
maxBodyLength: Infinity,
url: `${this.certs_url}/${this.certsEndpoint}`,
headers: {
'Content-Type': this.content_type,
Authorization: `Bearer ${token}`
},
data: JSON.stringify(payload)
}
return _axios.default
.request(options)
.then((response) => {
return response.data
})
.catch((error) => {
return error.response.data
})
}
ViewByThing (thing_id, token) {
// View certificates by thing_id
/**
* @method ViewByThing - Allows a logged in user to view a certificate serial once they
* provide a valid connected thing-id and token.
* @param {string} thing_id - The thing_id of the thing whose certificate is to be viewed.
* @param {string} token - The token to be used for authentication.
*
*/
const options = {
method: 'get',
maxBodyLength: Infinity,
url: `${this.certs_url}/serials/${thing_id}`,
headers: {
'Content-Type': this.content_type,
Authorization: `Bearer ${token}`
}
}
return _axios.default
.request(options)
.then((response) => {
return response.data
})
.catch((error) => {
return error.response.data
})
}
ViewBySerial (cert_id, token) {
// View certificate by cert_id
/**
* @method ViewBySerial - Allows a logged in user to view a certificate once they
* provide a valid cert-id and token.
* @param {string} cert_id - The cert_id of the certificate to be viewed.
* @param {string} token - The token to be used for authentication.
*
*/
const options = {
method: 'get',
maxBodyLength: Infinity,
url: `${this.certs_url}/${this.certsEndpoint}/${cert_id}`,
headers: {
'Content-Type': this.content_type,
Authorization: `Bearer ${token}`
}
}
return _axios.default
.request(options)
.then((response) => {
return response.data
})
.catch((error) => {
return error.response.data
})
}
Revoke (thing_id, token) {
// Revoke a certificate
/**
* @method Revoke - Allows a logged in user to delete a certificate once they
* provide a valid thing-id and token.
* @param {string} thing_id - The thing_id of the certificate to be revoked.
* @param {string} token - The token to be used for authentication.
*/
const options = {
method: 'delete',
maxBodyLength: Infinity,
url: `${this.certs_url}/${this.certsEndpoint}/${thing_id}`,
headers: {
'Content-Type': this.content_type,
Authorization: `Bearer ${token}`
}
}
return _axios.default
.request(options)
.then((_response) => {
return 'DELETED'
})
.catch((error) => {
return error.response.data
})
}
}
module.exports = Certs
},
{ axios: 8 }
],
3: [
function (require, module, exports) {
'use strict'
const _axios = _interopRequireDefault(require('axios'))
function _interopRequireDefault (obj) {
return obj?.__esModule ? obj : { default: obj }
}
// import fetch from "node-fetch";
class Channels {
// Channels API client
/**
* @class Channels -
* Channels API is used for managing Channels. It is used for creating new
* channels, retrieving them, updating them and disabling them
* @param {string} channels_url - URL to the Channels service
* @param {string} content_type - Content type for the requests which is an application
* json
* @param {string} channelsEndpoint - Endpoint for the channels' service.
* @returns {Object} -Channels object
*
*/
constructor (channels_url) {
this.channels_url = channels_url
this.content_type = 'application/json'
this.channelsEndpoint = 'channels'
}
Create (channel, token) {
// Creates a new channel
/**
* @method Create - Creates new channels when provided with a channel object
* with viable fresh information and a valid token.
* @param {Object} channel - Channel Object with a name and id.
* @param {String} token - An access token that is valid.
* @returns {Object} - User object.
* @example
* const channel = {
* "name": "channelName",
* "description": "long channel description",
* "parent_id": "bb7edb32-2eac-4aad-aebe-ed96fe073879",
* "metadata": {
* "domain": "example.com"
* },
* "status": "enabled",
* "owner_id": "bb7edb32-2eac-4aad-aebe-ed96fe073879"
* }
*
*/
const options = {
method: 'post',
maxBodyLength: Infinity,
url: `${this.channels_url}/${this.channelsEndpoint}`,
headers: {
'Content-Type': this.content_type,
Authorization: `Bearer ${token}`
},
data: JSON.stringify(channel)
}
return _axios.default
.request(options)
.then((response) => {
return response.data
})
.catch((error) => {
return error.response.data
})
}
CreateBulk (channels, token) {
// Creates multiple channels.
/**
* @method Create_bulk - Creates multiple channels when provided with a channel object
* with viable fresh information and a valid token.
* @param {List} channels - Channel Object with a name and id.
* @param {String} token - An access token that is valid.
* @returns {Object} - User object.
* @example
* const channels = [
* { "name": "channelA", "id": "bb7edb32-2eac-4aad-aebe-ed96fe073879" },
* { "name": "channelB", "id": "290b0f49-7a57-4b8c-9e4e-fbf17c6ab7d9" }
* ]
*/
const options = {
method: 'post',
maxBodyLength: Infinity,
url: `${this.channels_url}/${this.channelsEndpoint}/bulk`,
headers: {
'Content-Type': this.content_type,
Authorization: `Bearer ${token}`
},
data: JSON.stringify(channels)
}
return _axios.default
.request(options)
.then((response) => {
return response.data
})
.catch((error) => {
return error.response.data
})
}
Get (channel_id, token) {
// Retrieves channel with specified id.
/**
* @method Get - Retrieves channel with specified id and a valid token.
* @param {String} channel_id - Channel id.
* @param {String} token - An access token that is valid.
* @returns {Object} - Channel object.
*/
const options = {
method: 'get',
maxBodyLength: Infinity,
url: `${this.channels_url}/${this.channelsEndpoint}/${channel_id}`,
headers: {
'Content-Type': this.content_type,
Authorization: `Bearer ${token}`
}
}
return _axios.default
.request(options)
.then((response) => {
return response.data
})
.catch((error) => {
return error.response.data
})
}
GetByThing (channel_id, query_params, token) {
// Retrieves list of things connected to specified channel with pagination metadata.
/**
* @method GetByThing - Retrieves list of things connected to specified channel with pagination metadata.
* @param {String} channel_id - Channel id.
* @param {Object} query_params - Query parameters for the request.
* @param {String} token - An access token that is valid.
* @returns {List} - Things list.
*/
const options = {
method: 'get',
maxBodyLength: Infinity,
url: `${this.channels_url}/${
this.channelsEndpoint
}/${channel_id}/things?${new URLSearchParams(
query_params
).toString()}`,
headers: {
'Content-Type': this.content_type,
Authorization: `Bearer ${token}`
}
}
return _axios.default
.request(options)
.then((response) => {
return response.data
})
.catch((error) => {
return error.response.data
})
}
GetAll (query_params, token) {
// Provides a list of all channels with pagination metadata.
/**
* @method GetAll - Provides a list of all channels with pagination metadata.
* @param {Object} query_params - Query parameters for the request.
* @param {String} token - An access token that is valid.
* @returns {Object} - Channel Object.
*/
const options = {
method: 'get',
maxBodyLength: Infinity,
url: `${this.channels_url}/${
this.channelsEndpoint
}?${new URLSearchParams(query_params).toString()}`,
headers: {
'Content-Type': this.content_type,
Authorization: `Bearer ${token}`
}
}
return _axios.default
.request(options)
.then((response) => {
return response.data
})
.catch((error) => {
return error.response.data
})
}
Update (channel, token) {
// Updates channel with specified id.
/**
* @method Update - Updates channel with specified id.
* @param {Object} channel - Channel object with new information.
* @param {String} token - An access token that is valid.
* @returns {Object} - Channel Object.
*/
const options = {
method: 'put',
maxBodyLength: Infinity,
url: `${this.channels_url}/${this.channelsEndpoint}/${channel.id}`,
headers: {
'Content-Type': this.content_type,
Authorization: `Bearer ${token}`
},
data: JSON.stringify(channel)
}
return _axios.default
.request(options)
.then((response) => {
return response.data
})
.catch((error) => {
return error.response.data
})
}
Disable (channel, token) {
// Disables channel with specified id.
/**
* @method Disable - Disables channel with specified id.
* @param {Object} channel - Channel object with new information.
* @param {String} token - An access token that is valid.
* @returns {Object} - Channel Object.
*/
const options = {
method: 'post',
maxBodyLength: Infinity,
url: `${this.channels_url}/${this.channelsEndpoint}/${channel.id}/disable`,
headers: {
'Content-Type': this.content_type,
Authorization: `Bearer ${token}`
}
}
return _axios.default
.request(options)
.then((response) => {
return response.data
})
.catch((error) => {
return error.response.data
})
}
}
// export default Channels;
module.exports = Channels
},
{ axios: 8 }
],
4: [
function (require, module, exports) {
'use strict'
const _axios = _interopRequireDefault(require('axios'))
function _interopRequireDefault (obj) {
return obj?.__esModule ? obj : { default: obj }
}
// import Errors from "./errors.js";
class Groups {
// Groups API client.
/**
* @class Groups -
* Groups API client is used for managing groups. It is used for
* creating, updating, deleting, and retrieving groups.
* @param {string} groups_url - The URL of the Groups service.
* @param {string} content_type - The content type of the request.
* @param {string} groupsEndpoint - The endpoint of the Groups service.
* @returns {Groups} - Returns a Groups object.
*/
constructor (groups_url) {
this.groups_url = groups_url
this.content_type = 'application/json'
this.groupsEndpoint = 'groups'
}
// groupError = new Errors;
Create (group, token) {
// Create a new group.
/**
* @method Create - Creates a new group once the user is authenticated.
* and a valid token is provided. The group's parent or child status in the
* heirarchy can also be established.
* @param {object} group - The group object to be created.
* @param {string} token - The user's token.
* @example
* const group = {
* "name": "groupName",
* "description": "long group description",
* "parent_id": "bb7edb32-2eac-4aad-aebe-ed96fe073879",
* "metadata": {
* "domain": "example.com"
* },
* "status": "enabled",
* "owner_id": "bb7edb32-2eac-4aad-aebe-ed96fe073879"
* }
*/
const options = {
method: 'post',
maxBodyLength: Infinity,
url: `${this.groups_url}/${this.groupsEndpoint}`,
headers: {
'Content-Type': this.content_type,
Authorization: `Bearer ${token}`
},
data: JSON.stringify(group)
}
return _axios.default
.request(options)
.then((response) => {
return response.data
})
.catch((error) => {
return error.response.data
})
}
Get (group_id, token) {
// Get a group.
/**
* @method Get - Provide a group's information once given the group ID and a valid token.
* @param {string} group_id - The group's ID.
* @param {string} token - The user's access token.
* @returns {object} - Returns a group object.
* @example
* const group_id = "bb7edb32-2eac-4aad-aebe-ed96fe073879"
*
*/
const options = {
method: 'get',
maxBodyLength: Infinity,
url: `${this.groups_url}/${this.groupsEndpoint}/${group_id}`,
headers: {
'Content-Type': this.content_type,
Authorization: `Bearer ${token}`
}
}
return _axios.default
.request(options)
.then((response) => {
return response.data
})
.catch((error) => {
return error.response.data
})
}
GetAll (query_params, token) {
// Get all groups.
/**
* @method Get_all - Provides a list of all the groups in the database once given a valid token.
* @param {string} token - The user's access token.
* @param {Object} query_params - Query parameters.
* @returns {object} - Returns a list of all the groups in the database.
* @example
* const query_params = {
* "offset": 0,
* "limit": 10
* }
*
*/
const options = {
method: 'get',
maxBodyLength: Infinity,
url: `${this.groups_url}/${
this.groupsEndpoint
}?${new URLSearchParams(query_params).toString()}`,
headers: {
'Content-Type': this.content_type,
Authorization: `Bearer ${token}`
}
}
return _axios.default
.request(options)
.then((response) => {
return response.data
})
.catch((error) => {
return error.response.data
})
}
Update (group, token) {
// Updates a group's information such a name and metadata.
/**
* @method Update - Updates a group's information such a name and metadata when given a
* valid token and group ID.
* @param {object} group - The group object to be updated.
* @param {string} token - The user's access token.
* @returns {object} - Returns the updated group object.
* @example
* const group = {
* "id": "bb7edb32-2eac-4aad-aebe-ed96fe073879",
* "name": "groupName"
* }
*
*/
const options = {
method: 'put',
maxBodyLength: Infinity,
url: `${this.groups_url}/${this.groupsEndpoint}/${group.id}`,
headers: {
'Content-Type': this.content_type,
Authorization: `Bearer ${token}`
},
data: JSON.stringify(group)
}
return _axios.default
.request(options)
.then((response) => {
return response.data
})
.catch((error) => {
return error.response.data
})
}
Children (group_id, query_params, token) {
// Get a group's children.
/**
* @method Children - Provides a list of a groups' children.
* @param {string} group_id - The group's ID.
* @param {string} token - The user's access token.
* @param {object} query_params - The query parameters such as offset and limit.
* @returns {object} - Returns a list of a group's children.
*
*/
const options = {
method: 'get',
maxBodyLength: Infinity,
url: `${this.groups_url}/${
this.groupsEndpoint
}/${group_id}/children?${new URLSearchParams(
query_params
).toString()}`,
headers: {
'Content-Type': this.content_type,
Authorization: `Bearer ${token}`
}
}
return _axios.default
.request(options)
.then((response) => {
return response.data
})
.catch((error) => {
return error.response.data
})
}
Parents (group, query_params, token) {
// Get a group's parents.
/**
* @method Parents - Provides a list of a groups' parents when provided with
* a valid token and group ID.
* @param {string} group_id - The group's ID.
* @param {string} token - The user's access token.
* @param {object} query_params - The query parameters such as offset and limit.
* @returns {object} - Returns a list of a group's parents.
*
*/
const options = {
method: 'get',
maxBodyLength: Infinity,
url: `${this.groups_url}/${this.groupsEndpoint}/${
group.id
}/parents?${new URLSearchParams(query_params).toString()}`,
headers: {
'Content-Type': this.content_type,
Authorization: `Bearer ${token}`
}
}
return _axios.default
.request(options)
.then((response) => {
return response.data
})
.catch((error) => {
return error.response.data
})
}
Assign (group_id, member_id, member_type, token) {
// Assign a member to a group.
/**
* @method Assign -Assigns a user to a group when given a valid token, group ID,
* member ID, and member type. This allows the user to perform
* some action on the group.
* @param {string} group_id - The group's ID.
* @param {string} member_id - The member's ID.
* @param {Array} member_type - The member's actions that they can perform over the group.
* @param {string} token - The user's access token.
* @returns {string} - "Policy created".
*
*/
const payload = {
object: group_id,
subject: member_id,
actions: member_type
}
const options = {
method: 'post',
maxBodyLength: Infinity,
url: `${this.groups_url}/policies`,
headers: {
'Content-Type': this.content_type,
Authorization: `Bearer ${token}`
},
data: JSON.stringify(payload)
}
return _axios.default
.request(options)
.then((_response) => {
return 'Policy created'
})
.catch((error) => {
return error.response.data
})
}
Unassign (members_ids, group_id, token) {
// Unassign a member from a group.
/**
* @method Unassign - Deletes a user's policy over a group through unassigning them.
* Requires a valid token, ID's of members of the group and the group ID.
* @param {Array} members_ids - The members' IDs.
* @param {string} group_id - The group's ID.
* @param {string} token - The user's access token.
* @returns {string} - "Policy deleted"
*/
const payload = {
object: group_id,
subject: members_ids
}
const options = {
method: 'delete',
maxBodyLength: Infinity,
url: `${this.groups_url}/policies/${members_ids}/${group_id}`,
headers: {
'Content-Type': this.content_type,
Authorization: `Bearer ${token}`
},
data: JSON.stringify(payload)
}
return _axios.default
.request(options)
.then((response) => {