@3dverse/api 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.cjs.js CHANGED
@@ -2,765 +2,765 @@
2
2
 
3
3
  var axios = require('axios');
4
4
 
5
- /**
6
- * 3dverse v1.0
7
- * # 3dverse API
8
- *
9
- * Welcome to the 3dverse API. The 3dverse API scopes to an API key. Each development environment of an application requires a separate API key.
10
- * Through the API key, you can manage ownership, access, and permissions for each environment.
11
- * Each environment has its own set of users, groups, folders, and assets.
12
- *
13
- *
14
- * Contact: 3dverse Support (support@3dverse.com)
15
- *
16
- * NOTE: This file is auto generated by library-generator (https://gitlab.com/3dverse/libs/library-generator).
17
- * Do not edit this file class manually.
18
- */
19
- //--------------------------------------------------------------------------
20
- const axiosInstance = axios.create({
21
- baseURL: "https://api.3dverse.com/app/v1",
22
- operationId: "3dverse"
23
- });
24
- //------------------------------------------------------------------------------
25
- function setBaseURL(baseURL) {
26
- axiosInstance.defaults.baseURL = baseURL;
27
- }
28
- function listUsers({ offset = 0, limit = 10 }) {
29
- return axiosInstance({
30
- operationId: "listUsers",
31
- method: "get",
32
- url: "/users",
33
- params: {
34
- offset: offset,
35
- limit: limit
36
- }
37
- });
38
- }
39
- function registerUser({ username }) {
40
- return axiosInstance({
41
- operationId: "registerUser",
42
- method: "post",
43
- url: "/users",
44
- data: {
45
- username: username
46
- }
47
- });
48
- }
49
- function getUser({ user_id }) {
50
- return axiosInstance({
51
- operationId: "getUser",
52
- method: "get",
53
- url: "/users/" + user_id + ""
54
- });
55
- }
56
- //--------------------------------------------------------------------------
57
- // Updates the details of the target user.
58
- function updateUser({ user_id, username }) {
59
- return axiosInstance({
60
- operationId: "updateUser",
61
- method: "patch",
62
- url: "/users/" + user_id + "",
63
- data: {
64
- username: username
65
- }
66
- });
67
- }
68
- function deleteUser({ user_id }) {
69
- return axiosInstance({
70
- operationId: "deleteUser",
71
- method: "delete",
72
- url: "/users/" + user_id + ""
73
- });
74
- }
75
- function generateUserToken({ user_id, scope, ttl = '1h' }) {
76
- return axiosInstance({
77
- operationId: "generateUserToken",
78
- method: "post",
79
- url: "/users/" + user_id + "/tokens",
80
- data: {
81
- scope: scope,
82
- ttl: ttl
83
- }
84
- });
85
- }
86
- function getUserGroups({ user_id }) {
87
- return axiosInstance({
88
- operationId: "getUserGroups",
89
- method: "get",
90
- url: "/users/" + user_id + "/groups"
91
- });
92
- }
93
- function getUserUploadTasks({ user_id, offset = 0, limit = 10 }) {
94
- return axiosInstance({
95
- operationId: "getUserUploadTasks",
96
- method: "get",
97
- url: "/users/" + user_id + "/upload-tasks",
98
- params: {
99
- offset: offset,
100
- limit: limit
101
- }
102
- });
103
- }
104
- function createGroup({ group_name, group_description, members }) {
105
- return axiosInstance({
106
- operationId: "createGroup",
107
- method: "post",
108
- url: "/groups",
109
- data: {
110
- group_name: group_name,
111
- group_description: group_description,
112
- members: members
113
- }
114
- });
115
- }
116
- function getGroup({ group_id }) {
117
- return axiosInstance({
118
- operationId: "getGroup",
119
- method: "get",
120
- url: "/groups/" + group_id + ""
121
- });
122
- }
123
- //--------------------------------------------------------------------------
124
- // Updates a group details.
125
- function updateGroupDescription({ group_id, group_name, group_description }) {
126
- return axiosInstance({
127
- operationId: "updateGroupDescription",
128
- method: "patch",
129
- url: "/groups/" + group_id + "",
130
- data: {
131
- group_name: group_name,
132
- group_description: group_description
133
- }
134
- });
135
- }
136
- //--------------------------------------------------------------------------
137
- // Deletes a group and all its access rights.
138
- function deleteGroup({ group_id }) {
139
- return axiosInstance({
140
- operationId: "deleteGroup",
141
- method: "delete",
142
- url: "/groups/" + group_id + ""
143
- });
144
- }
145
- //--------------------------------------------------------------------------
146
- // Grants member access to the group.
147
- function grantMemberAccessToGroup({ group_id, member_type, member_id, group_access, folder_access }) {
148
- return axiosInstance({
149
- operationId: "grantMemberAccessToGroup",
150
- method: "put",
151
- url: "/groups/" + group_id + "/members/" + member_type + "/" + member_id + "",
152
- data: {
153
- group_access: group_access,
154
- folder_access: folder_access
155
- }
156
- });
157
- }
158
- //--------------------------------------------------------------------------
159
- // Revoke requested user access to group.
160
- function revokeMemberAccessToGroup({ group_id, member_type, member_id }) {
161
- return axiosInstance({
162
- operationId: "revokeMemberAccessToGroup",
163
- method: "delete",
164
- url: "/groups/" + group_id + "/members/" + member_type + "/" + member_id + ""
165
- });
166
- }
167
- function listFolders({ offset = 0, limit = 10 }) {
168
- return axiosInstance({
169
- operationId: "listFolders",
170
- method: "get",
171
- url: "/folders",
172
- params: {
173
- offset: offset,
174
- limit: limit
175
- }
176
- });
177
- }
178
- function createFolder({ folder_name, subfolders }) {
179
- return axiosInstance({
180
- operationId: "createFolder",
181
- method: "post",
182
- url: "/folders",
183
- data: {
184
- folder_name: folder_name,
185
- subfolders: subfolders
186
- }
187
- });
188
- }
189
- function getFolderInfo({ folder_id }) {
190
- return axiosInstance({
191
- operationId: "getFolderInfo",
192
- method: "get",
193
- url: "/folders/" + folder_id + ""
194
- });
195
- }
196
- //--------------------------------------------------------------------------
197
- // Move folders inside the specified folder.
198
- function moveFolders({ folder_id, folderIds }) {
199
- return axiosInstance({
200
- operationId: "moveFolders",
201
- method: "put",
202
- url: "/folders/" + folder_id + "",
203
- data: folderIds
204
- });
205
- }
206
- //--------------------------------------------------------------------------
207
- // Updates the folder details.
208
- function updateFolder({ folder_id, folder_name }) {
209
- return axiosInstance({
210
- operationId: "updateFolder",
211
- method: "patch",
212
- url: "/folders/" + folder_id + "",
213
- data: {
214
- folder_name: folder_name
215
- }
216
- });
217
- }
218
- //--------------------------------------------------------------------------
219
- // Deletes the requested folder. The target folder must be empty.
220
- function deleteFolder({ folder_id }) {
221
- return axiosInstance({
222
- operationId: "deleteFolder",
223
- method: "delete",
224
- url: "/folders/" + folder_id + ""
225
- });
226
- }
227
- function listFolderAccesses({ folder_id }) {
228
- return axiosInstance({
229
- operationId: "listFolderAccesses",
230
- method: "get",
231
- url: "/folders/" + folder_id + "/access"
232
- });
233
- }
234
- //--------------------------------------------------------------------------
235
- // Grants member access to the targeted folder.
236
- function grantMemberAccessToFolder({ folder_id, member_type, member_id, access }) {
237
- return axiosInstance({
238
- operationId: "grantMemberAccessToFolder",
239
- method: "put",
240
- url: "/folders/" + folder_id + "/access/" + member_type + "/" + member_id + "",
241
- data: {
242
- access: access
243
- }
244
- });
245
- }
246
- //--------------------------------------------------------------------------
247
- // Revokes member access to a target folder.
248
- function revokeMemberAccessToFolder({ folder_id, member_type, member_id }) {
249
- return axiosInstance({
250
- operationId: "revokeMemberAccessToFolder",
251
- method: "delete",
252
- url: "/folders/" + folder_id + "/access/" + member_type + "/" + member_id + ""
253
- });
254
- }
255
- function createSubfolder({ folder_id, folder_name, subfolders }) {
256
- return axiosInstance({
257
- operationId: "createSubfolder",
258
- method: "post",
259
- url: "/folders/" + folder_id + "/folders",
260
- data: {
261
- folder_name: folder_name,
262
- subfolders: subfolders
263
- }
264
- });
265
- }
266
- function listFolderSubFolders({ folder_id, depth = 0 }) {
267
- return axiosInstance({
268
- operationId: "listFolderSubFolders",
269
- method: "get",
270
- url: "/folders/" + folder_id + "/folders",
271
- params: {
272
- depth: depth
273
- }
274
- });
275
- }
276
- function uploadSourceFiles({ folder_id, body }) {
277
- return axiosInstance({
278
- operationId: "uploadSourceFiles",
279
- method: "post",
280
- url: "/folders/" + folder_id + "/source-files",
281
- headers: {
282
- "Content-Type": "multipart/form-data"
283
- },
284
- data: body
285
- });
286
- }
287
- function getSourceFilesInFolder({ folder_id, offset = 0, limit = 10 }) {
288
- return axiosInstance({
289
- operationId: "getSourceFilesInFolder",
290
- method: "get",
291
- url: "/folders/" + folder_id + "/source-files",
292
- params: {
293
- offset: offset,
294
- limit: limit
295
- }
296
- });
297
- }
298
- //--------------------------------------------------------------------------
299
- // Move source files inside the specified folder.
300
- function moveSourceFiles({ folder_id, sourceFileIds }) {
301
- return axiosInstance({
302
- operationId: "moveSourceFiles",
303
- method: "put",
304
- url: "/folders/" + folder_id + "/source-files",
305
- data: sourceFileIds
306
- });
307
- }
308
- function getUploadTasksInFolder({ folder_id, offset = 0, limit = 10 }) {
309
- return axiosInstance({
310
- operationId: "getUploadTasksInFolder",
311
- method: "get",
312
- url: "/folders/" + folder_id + "/upload-tasks",
313
- params: {
314
- offset: offset,
315
- limit: limit
316
- }
317
- });
318
- }
319
- function getFolderAssets({ folder_id, offset = 0, limit = 10 }) {
320
- return axiosInstance({
321
- operationId: "getFolderAssets",
322
- method: "get",
323
- url: "/folders/" + folder_id + "/assets",
324
- params: {
325
- offset: offset,
326
- limit: limit
327
- }
328
- });
329
- }
330
- //--------------------------------------------------------------------------
331
- // Move assets inside the specified folder.
332
- function moveAssets({ folder_id, assetIds }) {
333
- return axiosInstance({
334
- operationId: "moveAssets",
335
- method: "put",
336
- url: "/folders/" + folder_id + "/assets",
337
- data: assetIds
338
- });
339
- }
340
- function createAsset({ folder_id, asset_container_creatable, assetCreationOptions }) {
341
- return axiosInstance({
342
- operationId: "createAsset",
343
- method: "post",
344
- url: "/folders/" + folder_id + "/assets/" + asset_container_creatable + "",
345
- data: assetCreationOptions
346
- });
347
- }
348
- function getSessionsInFolder({ folder_id }) {
349
- return axiosInstance({
350
- operationId: "getSessionsInFolder",
351
- method: "get",
352
- url: "/folders/" + folder_id + "/sessions"
353
- });
354
- }
355
- function listSourceFiles({ offset = 0, limit = 10 }) {
356
- return axiosInstance({
357
- operationId: "listSourceFiles",
358
- method: "get",
359
- url: "/source-files",
360
- params: {
361
- offset: offset,
362
- limit: limit
363
- }
364
- });
365
- }
366
- //--------------------------------------------------------------------------
367
- // Deletes the target source files. Deleting a source file is permanent.
368
- function deleteSourceFiles({ sourceFileIds }) {
369
- return axiosInstance({
370
- operationId: "deleteSourceFiles",
371
- method: "delete",
372
- url: "/source-files",
373
- data: sourceFileIds
374
- });
375
- }
376
- //--------------------------------------------------------------------------
377
- // Downloads the target source file.
378
- function downloadSourceFile({ source_file_id }) {
379
- return axiosInstance({
380
- operationId: "downloadSourceFile",
381
- method: "get",
382
- url: "/source-files/" + source_file_id + "",
383
- responseType: "arraybuffer"
384
- });
385
- }
386
- function getSourceFileDetails({ source_file_id }) {
387
- return axiosInstance({
388
- operationId: "getSourceFileDetails",
389
- method: "get",
390
- url: "/source-files/" + source_file_id + "/details"
391
- });
392
- }
393
- //--------------------------------------------------------------------------
394
- // Updates details for a specific source file.
395
- function updateSourceFileDetails({ source_file_id, source_file_name }) {
396
- return axiosInstance({
397
- operationId: "updateSourceFileDetails",
398
- method: "patch",
399
- url: "/source-files/" + source_file_id + "/details",
400
- data: {
401
- source_file_name: source_file_name
402
- }
403
- });
404
- }
405
- function getSourceFileAssets({ source_file_id }) {
406
- return axiosInstance({
407
- operationId: "getSourceFileAssets",
408
- method: "get",
409
- url: "/source-files/" + source_file_id + "/assets"
410
- });
411
- }
412
- function getUploadTask({ upload_task_id }) {
413
- return axiosInstance({
414
- operationId: "getUploadTask",
415
- method: "get",
416
- url: "/upload-tasks/" + upload_task_id + ""
417
- });
418
- }
419
- function listAssets({ offset = 0, limit = 10 }) {
420
- return axiosInstance({
421
- operationId: "listAssets",
422
- method: "get",
423
- url: "/assets",
424
- params: {
425
- offset: offset,
426
- limit: limit
427
- }
428
- });
429
- }
430
- //--------------------------------------------------------------------------
431
- // Batch delete assets. You **MUST NOT** reference assets.
432
- function deleteAssets({ assetIds }) {
433
- return axiosInstance({
434
- operationId: "deleteAssets",
435
- method: "delete",
436
- url: "/assets",
437
- data: assetIds
438
- });
439
- }
440
- //--------------------------------------------------------------------------
441
- // Deletes the asset.
442
- function deleteAsset({ asset_container, asset_id }) {
443
- return axiosInstance({
444
- operationId: "deleteAsset",
445
- method: "delete",
446
- url: "/assets/" + asset_container + "/" + asset_id + ""
447
- });
448
- }
449
- function getAssetSourceFile({ asset_container, asset_id }) {
450
- return axiosInstance({
451
- operationId: "getAssetSourceFile",
452
- method: "get",
453
- url: "/assets/" + asset_container + "/" + asset_id + "/source-file"
454
- });
455
- }
456
- function getAssetDetails({ asset_container, asset_id }) {
457
- return axiosInstance({
458
- operationId: "getAssetDetails",
459
- method: "get",
460
- url: "/assets/" + asset_container + "/" + asset_id + "/details"
461
- });
462
- }
463
- function getAssetFolder({ asset_container, asset_id }) {
464
- return axiosInstance({
465
- operationId: "getAssetFolder",
466
- method: "get",
467
- url: "/assets/" + asset_container + "/" + asset_id + "/folder"
468
- });
469
- }
470
- function getAssetDependencies({ asset_container, asset_id, format = 'flat', depth = 'all', filter }) {
471
- return axiosInstance({
472
- operationId: "getAssetDependencies",
473
- method: "get",
474
- url: "/assets/" + asset_container + "/" + asset_id + "/dependencies",
475
- params: {
476
- format: format,
477
- depth: depth,
478
- filter: filter
479
- }
480
- });
481
- }
482
- function getAssetReferences({ asset_container, asset_id }) {
483
- return axiosInstance({
484
- operationId: "getAssetReferences",
485
- method: "get",
486
- url: "/assets/" + asset_container + "/" + asset_id + "/references"
487
- });
488
- }
489
- function getAssetDescription({ asset_container, asset_id }) {
490
- return axiosInstance({
491
- operationId: "getAssetDescription",
492
- method: "get",
493
- url: "/assets/" + asset_container + "/" + asset_id + "/description"
494
- });
495
- }
496
- function updateAssetDescription({ asset_container, asset_id, assetDescription }) {
497
- return axiosInstance({
498
- operationId: "updateAssetDescription",
499
- method: "patch",
500
- url: "/assets/" + asset_container + "/" + asset_id + "/description",
501
- data: assetDescription
502
- });
503
- }
504
- //--------------------------------------------------------------------------
505
- // Gets the asset payload from the specified asset.
506
- function getAssetPayload({ asset_container_with_payload, asset_id }) {
507
- return axiosInstance({
508
- operationId: "getAssetPayload",
509
- method: "get",
510
- url: "/assets/" + asset_container_with_payload + "/" + asset_id + "/payload",
511
- responseType: "arraybuffer"
512
- });
513
- }
514
- function getAssetHistory({ asset_container, asset_id }) {
515
- return axiosInstance({
516
- operationId: "getAssetHistory",
517
- method: "get",
518
- url: "/assets/" + asset_container + "/" + asset_id + "/history"
519
- });
520
- }
521
- function getAssetMeta({ asset_container, asset_id }) {
522
- return axiosInstance({
523
- operationId: "getAssetMeta",
524
- method: "get",
525
- url: "/assets/" + asset_container + "/" + asset_id + "/meta"
526
- });
527
- }
528
- //--------------------------------------------------------------------------
529
- // Gets the code of the specified asset.
530
- function getAssetCode({ asset_container_with_code, asset_id }) {
531
- return axiosInstance({
532
- operationId: "getAssetCode",
533
- method: "get",
534
- url: "/assets/" + asset_container_with_code + "/" + asset_id + "/code"
535
- });
536
- }
537
- //--------------------------------------------------------------------------
538
- // Gets the asset thumbnail from the specified asset.
539
- function getAssetThumbnail({ asset_container, asset_id, size, default_url }) {
540
- return axiosInstance({
541
- operationId: "getAssetThumbnail",
542
- method: "get",
543
- url: "/assets/" + asset_container + "/" + asset_id + "/thumbnail",
544
- params: {
545
- size: size,
546
- default_url: default_url
547
- }
548
- });
549
- }
550
- //--------------------------------------------------------------------------
551
- // Assigns a thumbnail to the specified asset.
552
- function setAssetThumbnail({ asset_container, asset_id, body }, contentType) {
553
- return axiosInstance({
554
- operationId: "setAssetThumbnail",
555
- method: "put",
556
- url: "/assets/" + asset_container + "/" + asset_id + "/thumbnail",
557
- headers: {
558
- "Content-Type": contentType
559
- },
560
- data: body
561
- });
562
- }
563
- function getAssetCustomTypes({ asset_container_with_custom_types, asset_id }) {
564
- return axiosInstance({
565
- operationId: "getAssetCustomTypes",
566
- method: "get",
567
- url: "/assets/" + asset_container_with_custom_types + "/" + asset_id + "/custom-types"
568
- });
569
- }
570
- //--------------------------------------------------------------------------
571
- // Packages and downloads the target asset.
572
- function packageAsset({ asset_container, asset_id }) {
573
- return axiosInstance({
574
- operationId: "packageAsset",
575
- method: "get",
576
- url: "/assets/" + asset_container + "/" + asset_id + "/package",
577
- responseType: "arraybuffer"
578
- });
579
- }
580
- //--------------------------------------------------------------------------
581
- // Downloads an asset payload in a given format. Only mesh is supported for the moment. This endpoint requires special export permission.
582
- function exportAsset({ asset_container_exportable, asset_id, format, scale = 1 }) {
583
- return axiosInstance({
584
- operationId: "exportAsset",
585
- method: "get",
586
- url: "/assets/" + asset_container_exportable + "/" + asset_id + "/exports/" + format + "",
587
- responseType: "arraybuffer",
588
- params: {
589
- scale: scale
590
- }
591
- });
592
- }
593
- function getSceneSessions({ scene_id }) {
594
- return axiosInstance({
595
- operationId: "getSceneSessions",
596
- method: "get",
597
- url: "/assets/scenes/" + scene_id + "/sessions"
598
- });
599
- }
600
- function getSceneAABB({ scene_id }) {
601
- return axiosInstance({
602
- operationId: "getSceneAABB",
603
- method: "get",
604
- url: "/assets/scenes/" + scene_id + "/aabb"
605
- });
606
- }
607
- function getEntity({ scene_id, entity_id, compute_global_transform = false }) {
608
- return axiosInstance({
609
- operationId: "getEntity",
610
- method: "get",
611
- url: "/assets/scenes/" + scene_id + "/entities/" + entity_id + "",
612
- params: {
613
- compute_global_transform: compute_global_transform
614
- }
615
- });
616
- }
617
- function updateEntity({ scene_id, entity_id, entity }) {
618
- return axiosInstance({
619
- operationId: "updateEntity",
620
- method: "patch",
621
- url: "/assets/scenes/" + scene_id + "/entities/" + entity_id + "",
622
- data: entity
623
- });
624
- }
625
- //--------------------------------------------------------------------------
626
- // Delete a specific entity from a scene
627
- function deleteEntity({ scene_id, entity_id }) {
628
- return axiosInstance({
629
- operationId: "deleteEntity",
630
- method: "delete",
631
- url: "/assets/scenes/" + scene_id + "/entities/" + entity_id + ""
632
- });
633
- }
634
- function createSession({ scene_id }) {
635
- return axiosInstance({
636
- operationId: "createSession",
637
- method: "post",
638
- url: "/sessions",
639
- data: {
640
- scene_id: scene_id
641
- }
642
- });
643
- }
644
- function getSession({ session_id }) {
645
- return axiosInstance({
646
- operationId: "getSession",
647
- method: "get",
648
- url: "/sessions/" + session_id + ""
649
- });
650
- }
651
- //--------------------------------------------------------------------------
652
- // Forcefully terminates a session.
653
- function killSession({ session_id }) {
654
- return axiosInstance({
655
- operationId: "killSession",
656
- method: "delete",
657
- url: "/sessions/" + session_id + ""
658
- });
659
- }
660
- function joinSession({ session_id }) {
661
- return axiosInstance({
662
- operationId: "joinSession",
663
- method: "post",
664
- url: "/sessions/" + session_id + "/clients"
665
- });
666
- }
667
- //--------------------------------------------------------------------------
668
- // Kick a client from a running session.
669
- function kickClientFromSession({ session_id, client_id }) {
670
- return axiosInstance({
671
- operationId: "kickClientFromSession",
672
- method: "delete",
673
- url: "/sessions/" + session_id + "/clients/" + client_id + ""
674
- });
675
- }
676
- function joinSessionAsGuest() {
677
- return axiosInstance({
678
- operationId: "joinSessionAsGuest",
679
- method: "post",
680
- url: "/sessions/guests"
681
- });
682
- }
683
- function generateGuestToken({ session_id }) {
684
- return axiosInstance({
685
- operationId: "generateGuestToken",
686
- method: "post",
687
- url: "/sessions/" + session_id + "/guests"
688
- });
5
+ /**
6
+ * 3dverse v1.0
7
+ * # 3dverse API
8
+ *
9
+ * Welcome to the 3dverse API. The 3dverse API scopes to an API key. Each development environment of an application requires a separate API key.
10
+ * Through the API key, you can manage ownership, access, and permissions for each environment.
11
+ * Each environment has its own set of users, groups, folders, and assets.
12
+ *
13
+ *
14
+ * Contact: 3dverse Support (support@3dverse.com)
15
+ *
16
+ * NOTE: This file is auto generated by library-generator (https://gitlab.com/3dverse/libs/library-generator).
17
+ * Do not edit this file class manually.
18
+ */
19
+ //--------------------------------------------------------------------------
20
+ const axiosInstance = axios.create({
21
+ baseURL: "https://api.3dverse.com/app/v1",
22
+ operationId: "3dverse"
23
+ });
24
+ //------------------------------------------------------------------------------
25
+ function setBaseURL(baseURL) {
26
+ axiosInstance.defaults.baseURL = baseURL;
27
+ }
28
+ function listUsers({ offset = 0, limit = 10 }) {
29
+ return axiosInstance({
30
+ operationId: "listUsers",
31
+ method: "get",
32
+ url: "/users",
33
+ params: {
34
+ offset: offset,
35
+ limit: limit
36
+ }
37
+ });
38
+ }
39
+ function registerUser({ username }) {
40
+ return axiosInstance({
41
+ operationId: "registerUser",
42
+ method: "post",
43
+ url: "/users",
44
+ data: {
45
+ username: username
46
+ }
47
+ });
48
+ }
49
+ function getUser({ user_id }) {
50
+ return axiosInstance({
51
+ operationId: "getUser",
52
+ method: "get",
53
+ url: "/users/" + user_id + ""
54
+ });
55
+ }
56
+ //--------------------------------------------------------------------------
57
+ // Updates the details of the target user.
58
+ function updateUser({ user_id, username }) {
59
+ return axiosInstance({
60
+ operationId: "updateUser",
61
+ method: "patch",
62
+ url: "/users/" + user_id + "",
63
+ data: {
64
+ username: username
65
+ }
66
+ });
67
+ }
68
+ function deleteUser({ user_id }) {
69
+ return axiosInstance({
70
+ operationId: "deleteUser",
71
+ method: "delete",
72
+ url: "/users/" + user_id + ""
73
+ });
74
+ }
75
+ function generateUserToken({ user_id, scope, ttl = '1h' }) {
76
+ return axiosInstance({
77
+ operationId: "generateUserToken",
78
+ method: "post",
79
+ url: "/users/" + user_id + "/tokens",
80
+ data: {
81
+ scope: scope,
82
+ ttl: ttl
83
+ }
84
+ });
85
+ }
86
+ function getUserGroups({ user_id }) {
87
+ return axiosInstance({
88
+ operationId: "getUserGroups",
89
+ method: "get",
90
+ url: "/users/" + user_id + "/groups"
91
+ });
92
+ }
93
+ function getUserUploadTasks({ user_id, offset = 0, limit = 10 }) {
94
+ return axiosInstance({
95
+ operationId: "getUserUploadTasks",
96
+ method: "get",
97
+ url: "/users/" + user_id + "/upload-tasks",
98
+ params: {
99
+ offset: offset,
100
+ limit: limit
101
+ }
102
+ });
103
+ }
104
+ function createGroup({ group_name, group_description, members }) {
105
+ return axiosInstance({
106
+ operationId: "createGroup",
107
+ method: "post",
108
+ url: "/groups",
109
+ data: {
110
+ group_name: group_name,
111
+ group_description: group_description,
112
+ members: members
113
+ }
114
+ });
115
+ }
116
+ function getGroup({ group_id }) {
117
+ return axiosInstance({
118
+ operationId: "getGroup",
119
+ method: "get",
120
+ url: "/groups/" + group_id + ""
121
+ });
122
+ }
123
+ //--------------------------------------------------------------------------
124
+ // Updates a group details.
125
+ function updateGroupDescription({ group_id, group_name, group_description }) {
126
+ return axiosInstance({
127
+ operationId: "updateGroupDescription",
128
+ method: "patch",
129
+ url: "/groups/" + group_id + "",
130
+ data: {
131
+ group_name: group_name,
132
+ group_description: group_description
133
+ }
134
+ });
135
+ }
136
+ //--------------------------------------------------------------------------
137
+ // Deletes a group and all its access rights.
138
+ function deleteGroup({ group_id }) {
139
+ return axiosInstance({
140
+ operationId: "deleteGroup",
141
+ method: "delete",
142
+ url: "/groups/" + group_id + ""
143
+ });
144
+ }
145
+ //--------------------------------------------------------------------------
146
+ // Grants member access to the group.
147
+ function grantMemberAccessToGroup({ group_id, member_type, member_id, group_access, folder_access }) {
148
+ return axiosInstance({
149
+ operationId: "grantMemberAccessToGroup",
150
+ method: "put",
151
+ url: "/groups/" + group_id + "/members/" + member_type + "/" + member_id + "",
152
+ data: {
153
+ group_access: group_access,
154
+ folder_access: folder_access
155
+ }
156
+ });
157
+ }
158
+ //--------------------------------------------------------------------------
159
+ // Revoke requested user access to group.
160
+ function revokeMemberAccessToGroup({ group_id, member_type, member_id }) {
161
+ return axiosInstance({
162
+ operationId: "revokeMemberAccessToGroup",
163
+ method: "delete",
164
+ url: "/groups/" + group_id + "/members/" + member_type + "/" + member_id + ""
165
+ });
166
+ }
167
+ function listFolders({ offset = 0, limit = 10 }) {
168
+ return axiosInstance({
169
+ operationId: "listFolders",
170
+ method: "get",
171
+ url: "/folders",
172
+ params: {
173
+ offset: offset,
174
+ limit: limit
175
+ }
176
+ });
177
+ }
178
+ function createFolder({ folder_name, subfolders }) {
179
+ return axiosInstance({
180
+ operationId: "createFolder",
181
+ method: "post",
182
+ url: "/folders",
183
+ data: {
184
+ folder_name: folder_name,
185
+ subfolders: subfolders
186
+ }
187
+ });
188
+ }
189
+ function getFolderInfo({ folder_id }) {
190
+ return axiosInstance({
191
+ operationId: "getFolderInfo",
192
+ method: "get",
193
+ url: "/folders/" + folder_id + ""
194
+ });
195
+ }
196
+ //--------------------------------------------------------------------------
197
+ // Move folders inside the specified folder.
198
+ function moveFolders({ folder_id, folderIds }) {
199
+ return axiosInstance({
200
+ operationId: "moveFolders",
201
+ method: "put",
202
+ url: "/folders/" + folder_id + "",
203
+ data: folderIds
204
+ });
205
+ }
206
+ //--------------------------------------------------------------------------
207
+ // Updates the folder details.
208
+ function updateFolder({ folder_id, folder_name }) {
209
+ return axiosInstance({
210
+ operationId: "updateFolder",
211
+ method: "patch",
212
+ url: "/folders/" + folder_id + "",
213
+ data: {
214
+ folder_name: folder_name
215
+ }
216
+ });
217
+ }
218
+ //--------------------------------------------------------------------------
219
+ // Deletes the requested folder. The target folder must be empty.
220
+ function deleteFolder({ folder_id }) {
221
+ return axiosInstance({
222
+ operationId: "deleteFolder",
223
+ method: "delete",
224
+ url: "/folders/" + folder_id + ""
225
+ });
226
+ }
227
+ function listFolderAccesses({ folder_id }) {
228
+ return axiosInstance({
229
+ operationId: "listFolderAccesses",
230
+ method: "get",
231
+ url: "/folders/" + folder_id + "/access"
232
+ });
233
+ }
234
+ //--------------------------------------------------------------------------
235
+ // Grants member access to the targeted folder.
236
+ function grantMemberAccessToFolder({ folder_id, member_type, member_id, access }) {
237
+ return axiosInstance({
238
+ operationId: "grantMemberAccessToFolder",
239
+ method: "put",
240
+ url: "/folders/" + folder_id + "/access/" + member_type + "/" + member_id + "",
241
+ data: {
242
+ access: access
243
+ }
244
+ });
245
+ }
246
+ //--------------------------------------------------------------------------
247
+ // Revokes member access to a target folder.
248
+ function revokeMemberAccessToFolder({ folder_id, member_type, member_id }) {
249
+ return axiosInstance({
250
+ operationId: "revokeMemberAccessToFolder",
251
+ method: "delete",
252
+ url: "/folders/" + folder_id + "/access/" + member_type + "/" + member_id + ""
253
+ });
254
+ }
255
+ function createSubfolder({ folder_id, folder_name, subfolders }) {
256
+ return axiosInstance({
257
+ operationId: "createSubfolder",
258
+ method: "post",
259
+ url: "/folders/" + folder_id + "/folders",
260
+ data: {
261
+ folder_name: folder_name,
262
+ subfolders: subfolders
263
+ }
264
+ });
265
+ }
266
+ function listFolderSubFolders({ folder_id, depth = 0 }) {
267
+ return axiosInstance({
268
+ operationId: "listFolderSubFolders",
269
+ method: "get",
270
+ url: "/folders/" + folder_id + "/folders",
271
+ params: {
272
+ depth: depth
273
+ }
274
+ });
275
+ }
276
+ function uploadSourceFiles({ folder_id, body }) {
277
+ return axiosInstance({
278
+ operationId: "uploadSourceFiles",
279
+ method: "post",
280
+ url: "/folders/" + folder_id + "/source-files",
281
+ headers: {
282
+ "Content-Type": "multipart/form-data"
283
+ },
284
+ data: body
285
+ });
286
+ }
287
+ function getSourceFilesInFolder({ folder_id, offset = 0, limit = 10 }) {
288
+ return axiosInstance({
289
+ operationId: "getSourceFilesInFolder",
290
+ method: "get",
291
+ url: "/folders/" + folder_id + "/source-files",
292
+ params: {
293
+ offset: offset,
294
+ limit: limit
295
+ }
296
+ });
297
+ }
298
+ //--------------------------------------------------------------------------
299
+ // Move source files inside the specified folder.
300
+ function moveSourceFiles({ folder_id, sourceFileIds }) {
301
+ return axiosInstance({
302
+ operationId: "moveSourceFiles",
303
+ method: "put",
304
+ url: "/folders/" + folder_id + "/source-files",
305
+ data: sourceFileIds
306
+ });
307
+ }
308
+ function getUploadTasksInFolder({ folder_id, offset = 0, limit = 10 }) {
309
+ return axiosInstance({
310
+ operationId: "getUploadTasksInFolder",
311
+ method: "get",
312
+ url: "/folders/" + folder_id + "/upload-tasks",
313
+ params: {
314
+ offset: offset,
315
+ limit: limit
316
+ }
317
+ });
318
+ }
319
+ function getFolderAssets({ folder_id, offset = 0, limit = 10 }) {
320
+ return axiosInstance({
321
+ operationId: "getFolderAssets",
322
+ method: "get",
323
+ url: "/folders/" + folder_id + "/assets",
324
+ params: {
325
+ offset: offset,
326
+ limit: limit
327
+ }
328
+ });
329
+ }
330
+ //--------------------------------------------------------------------------
331
+ // Move assets inside the specified folder.
332
+ function moveAssets({ folder_id, assetIds }) {
333
+ return axiosInstance({
334
+ operationId: "moveAssets",
335
+ method: "put",
336
+ url: "/folders/" + folder_id + "/assets",
337
+ data: assetIds
338
+ });
339
+ }
340
+ function createAsset({ folder_id, asset_container_creatable, assetCreationOptions }) {
341
+ return axiosInstance({
342
+ operationId: "createAsset",
343
+ method: "post",
344
+ url: "/folders/" + folder_id + "/assets/" + asset_container_creatable + "",
345
+ data: assetCreationOptions
346
+ });
347
+ }
348
+ function getSessionsInFolder({ folder_id }) {
349
+ return axiosInstance({
350
+ operationId: "getSessionsInFolder",
351
+ method: "get",
352
+ url: "/folders/" + folder_id + "/sessions"
353
+ });
354
+ }
355
+ function listSourceFiles({ offset = 0, limit = 10 }) {
356
+ return axiosInstance({
357
+ operationId: "listSourceFiles",
358
+ method: "get",
359
+ url: "/source-files",
360
+ params: {
361
+ offset: offset,
362
+ limit: limit
363
+ }
364
+ });
365
+ }
366
+ //--------------------------------------------------------------------------
367
+ // Deletes the target source files. Deleting a source file is permanent.
368
+ function deleteSourceFiles({ sourceFileIds }) {
369
+ return axiosInstance({
370
+ operationId: "deleteSourceFiles",
371
+ method: "delete",
372
+ url: "/source-files",
373
+ data: sourceFileIds
374
+ });
375
+ }
376
+ //--------------------------------------------------------------------------
377
+ // Downloads the target source file.
378
+ function downloadSourceFile({ source_file_id }) {
379
+ return axiosInstance({
380
+ operationId: "downloadSourceFile",
381
+ method: "get",
382
+ url: "/source-files/" + source_file_id + "",
383
+ responseType: "arraybuffer"
384
+ });
385
+ }
386
+ function getSourceFileDetails({ source_file_id }) {
387
+ return axiosInstance({
388
+ operationId: "getSourceFileDetails",
389
+ method: "get",
390
+ url: "/source-files/" + source_file_id + "/details"
391
+ });
392
+ }
393
+ //--------------------------------------------------------------------------
394
+ // Updates details for a specific source file.
395
+ function updateSourceFileDetails({ source_file_id, source_file_name }) {
396
+ return axiosInstance({
397
+ operationId: "updateSourceFileDetails",
398
+ method: "patch",
399
+ url: "/source-files/" + source_file_id + "/details",
400
+ data: {
401
+ source_file_name: source_file_name
402
+ }
403
+ });
404
+ }
405
+ function getSourceFileAssets({ source_file_id }) {
406
+ return axiosInstance({
407
+ operationId: "getSourceFileAssets",
408
+ method: "get",
409
+ url: "/source-files/" + source_file_id + "/assets"
410
+ });
411
+ }
412
+ function getUploadTask({ upload_task_id }) {
413
+ return axiosInstance({
414
+ operationId: "getUploadTask",
415
+ method: "get",
416
+ url: "/upload-tasks/" + upload_task_id + ""
417
+ });
418
+ }
419
+ function listAssets({ offset = 0, limit = 10 }) {
420
+ return axiosInstance({
421
+ operationId: "listAssets",
422
+ method: "get",
423
+ url: "/assets",
424
+ params: {
425
+ offset: offset,
426
+ limit: limit
427
+ }
428
+ });
429
+ }
430
+ //--------------------------------------------------------------------------
431
+ // Batch delete assets. You **MUST NOT** reference assets.
432
+ function deleteAssets({ assetIds }) {
433
+ return axiosInstance({
434
+ operationId: "deleteAssets",
435
+ method: "delete",
436
+ url: "/assets",
437
+ data: assetIds
438
+ });
439
+ }
440
+ //--------------------------------------------------------------------------
441
+ // Deletes the asset.
442
+ function deleteAsset({ asset_container, asset_id }) {
443
+ return axiosInstance({
444
+ operationId: "deleteAsset",
445
+ method: "delete",
446
+ url: "/assets/" + asset_container + "/" + asset_id + ""
447
+ });
448
+ }
449
+ function getAssetSourceFile({ asset_container, asset_id }) {
450
+ return axiosInstance({
451
+ operationId: "getAssetSourceFile",
452
+ method: "get",
453
+ url: "/assets/" + asset_container + "/" + asset_id + "/source-file"
454
+ });
455
+ }
456
+ function getAssetDetails({ asset_container, asset_id }) {
457
+ return axiosInstance({
458
+ operationId: "getAssetDetails",
459
+ method: "get",
460
+ url: "/assets/" + asset_container + "/" + asset_id + "/details"
461
+ });
462
+ }
463
+ function getAssetFolder({ asset_container, asset_id }) {
464
+ return axiosInstance({
465
+ operationId: "getAssetFolder",
466
+ method: "get",
467
+ url: "/assets/" + asset_container + "/" + asset_id + "/folder"
468
+ });
469
+ }
470
+ function getAssetDependencies({ asset_container, asset_id, format = 'flat', depth = 'all', filter }) {
471
+ return axiosInstance({
472
+ operationId: "getAssetDependencies",
473
+ method: "get",
474
+ url: "/assets/" + asset_container + "/" + asset_id + "/dependencies",
475
+ params: {
476
+ format: format,
477
+ depth: depth,
478
+ filter: filter
479
+ }
480
+ });
481
+ }
482
+ function getAssetReferences({ asset_container, asset_id }) {
483
+ return axiosInstance({
484
+ operationId: "getAssetReferences",
485
+ method: "get",
486
+ url: "/assets/" + asset_container + "/" + asset_id + "/references"
487
+ });
488
+ }
489
+ function getAssetDescription({ asset_container, asset_id }) {
490
+ return axiosInstance({
491
+ operationId: "getAssetDescription",
492
+ method: "get",
493
+ url: "/assets/" + asset_container + "/" + asset_id + "/description"
494
+ });
495
+ }
496
+ function updateAssetDescription({ asset_container, asset_id, assetDescription }) {
497
+ return axiosInstance({
498
+ operationId: "updateAssetDescription",
499
+ method: "patch",
500
+ url: "/assets/" + asset_container + "/" + asset_id + "/description",
501
+ data: assetDescription
502
+ });
503
+ }
504
+ //--------------------------------------------------------------------------
505
+ // Gets the asset payload from the specified asset.
506
+ function getAssetPayload({ asset_container_with_payload, asset_id }) {
507
+ return axiosInstance({
508
+ operationId: "getAssetPayload",
509
+ method: "get",
510
+ url: "/assets/" + asset_container_with_payload + "/" + asset_id + "/payload",
511
+ responseType: "arraybuffer"
512
+ });
513
+ }
514
+ function getAssetHistory({ asset_container, asset_id }) {
515
+ return axiosInstance({
516
+ operationId: "getAssetHistory",
517
+ method: "get",
518
+ url: "/assets/" + asset_container + "/" + asset_id + "/history"
519
+ });
520
+ }
521
+ function getAssetMeta({ asset_container, asset_id }) {
522
+ return axiosInstance({
523
+ operationId: "getAssetMeta",
524
+ method: "get",
525
+ url: "/assets/" + asset_container + "/" + asset_id + "/meta"
526
+ });
527
+ }
528
+ //--------------------------------------------------------------------------
529
+ // Gets the code of the specified asset.
530
+ function getAssetCode({ asset_container_with_code, asset_id }) {
531
+ return axiosInstance({
532
+ operationId: "getAssetCode",
533
+ method: "get",
534
+ url: "/assets/" + asset_container_with_code + "/" + asset_id + "/code"
535
+ });
536
+ }
537
+ //--------------------------------------------------------------------------
538
+ // Gets the asset thumbnail from the specified asset.
539
+ function getAssetThumbnail({ asset_container, asset_id, size, default_url }) {
540
+ return axiosInstance({
541
+ operationId: "getAssetThumbnail",
542
+ method: "get",
543
+ url: "/assets/" + asset_container + "/" + asset_id + "/thumbnail",
544
+ params: {
545
+ size: size,
546
+ default_url: default_url
547
+ }
548
+ });
549
+ }
550
+ //--------------------------------------------------------------------------
551
+ // Assigns a thumbnail to the specified asset.
552
+ function setAssetThumbnail({ asset_container, asset_id, body }, contentType) {
553
+ return axiosInstance({
554
+ operationId: "setAssetThumbnail",
555
+ method: "put",
556
+ url: "/assets/" + asset_container + "/" + asset_id + "/thumbnail",
557
+ headers: {
558
+ "Content-Type": contentType
559
+ },
560
+ data: body
561
+ });
562
+ }
563
+ function getAssetCustomTypes({ asset_container_with_custom_types, asset_id }) {
564
+ return axiosInstance({
565
+ operationId: "getAssetCustomTypes",
566
+ method: "get",
567
+ url: "/assets/" + asset_container_with_custom_types + "/" + asset_id + "/custom-types"
568
+ });
569
+ }
570
+ //--------------------------------------------------------------------------
571
+ // Packages and downloads the target asset.
572
+ function packageAsset({ asset_container, asset_id }) {
573
+ return axiosInstance({
574
+ operationId: "packageAsset",
575
+ method: "get",
576
+ url: "/assets/" + asset_container + "/" + asset_id + "/package",
577
+ responseType: "arraybuffer"
578
+ });
579
+ }
580
+ //--------------------------------------------------------------------------
581
+ // Downloads an asset payload in a given format. Only mesh is supported for the moment. This endpoint requires special export permission.
582
+ function exportAsset({ asset_container_exportable, asset_id, format, scale = 1 }) {
583
+ return axiosInstance({
584
+ operationId: "exportAsset",
585
+ method: "get",
586
+ url: "/assets/" + asset_container_exportable + "/" + asset_id + "/exports/" + format + "",
587
+ responseType: "arraybuffer",
588
+ params: {
589
+ scale: scale
590
+ }
591
+ });
592
+ }
593
+ function getSceneSessions({ scene_id }) {
594
+ return axiosInstance({
595
+ operationId: "getSceneSessions",
596
+ method: "get",
597
+ url: "/assets/scenes/" + scene_id + "/sessions"
598
+ });
599
+ }
600
+ function getSceneAABB({ scene_id }) {
601
+ return axiosInstance({
602
+ operationId: "getSceneAABB",
603
+ method: "get",
604
+ url: "/assets/scenes/" + scene_id + "/aabb"
605
+ });
606
+ }
607
+ function getEntity({ scene_id, entity_id, compute_global_transform = false }) {
608
+ return axiosInstance({
609
+ operationId: "getEntity",
610
+ method: "get",
611
+ url: "/assets/scenes/" + scene_id + "/entities/" + entity_id + "",
612
+ params: {
613
+ compute_global_transform: compute_global_transform
614
+ }
615
+ });
616
+ }
617
+ function updateEntity({ scene_id, entity_id, entity }) {
618
+ return axiosInstance({
619
+ operationId: "updateEntity",
620
+ method: "patch",
621
+ url: "/assets/scenes/" + scene_id + "/entities/" + entity_id + "",
622
+ data: entity
623
+ });
624
+ }
625
+ //--------------------------------------------------------------------------
626
+ // Delete a specific entity from a scene
627
+ function deleteEntity({ scene_id, entity_id }) {
628
+ return axiosInstance({
629
+ operationId: "deleteEntity",
630
+ method: "delete",
631
+ url: "/assets/scenes/" + scene_id + "/entities/" + entity_id + ""
632
+ });
633
+ }
634
+ function createSession({ scene_id }) {
635
+ return axiosInstance({
636
+ operationId: "createSession",
637
+ method: "post",
638
+ url: "/sessions",
639
+ data: {
640
+ scene_id: scene_id
641
+ }
642
+ });
643
+ }
644
+ function getSession({ session_id }) {
645
+ return axiosInstance({
646
+ operationId: "getSession",
647
+ method: "get",
648
+ url: "/sessions/" + session_id + ""
649
+ });
650
+ }
651
+ //--------------------------------------------------------------------------
652
+ // Forcefully terminates a session.
653
+ function killSession({ session_id }) {
654
+ return axiosInstance({
655
+ operationId: "killSession",
656
+ method: "delete",
657
+ url: "/sessions/" + session_id + ""
658
+ });
659
+ }
660
+ function joinSession({ session_id }) {
661
+ return axiosInstance({
662
+ operationId: "joinSession",
663
+ method: "post",
664
+ url: "/sessions/" + session_id + "/clients"
665
+ });
666
+ }
667
+ //--------------------------------------------------------------------------
668
+ // Kick a client from a running session.
669
+ function kickClientFromSession({ session_id, client_id }) {
670
+ return axiosInstance({
671
+ operationId: "kickClientFromSession",
672
+ method: "delete",
673
+ url: "/sessions/" + session_id + "/clients/" + client_id + ""
674
+ });
675
+ }
676
+ function joinSessionAsGuest() {
677
+ return axiosInstance({
678
+ operationId: "joinSessionAsGuest",
679
+ method: "post",
680
+ url: "/sessions/guests"
681
+ });
682
+ }
683
+ function generateGuestToken({ session_id }) {
684
+ return axiosInstance({
685
+ operationId: "generateGuestToken",
686
+ method: "post",
687
+ url: "/sessions/" + session_id + "/guests"
688
+ });
689
689
  }
690
690
 
691
- //------------------------------------------------------------------------------
692
- function setApiKey(apiKey) {
693
- axiosInstance.defaults.headers.common['api_key'] = apiKey;
694
- delete axiosInstance.defaults.headers.common['user_token'];
695
- }
696
- //------------------------------------------------------------------------------
697
- function setUserToken(userToken) {
698
- axiosInstance.defaults.headers.common['user_token'] = userToken;
699
- delete axiosInstance.defaults.headers.common['api_key'];
700
- }
701
- //------------------------------------------------------------------------------
702
- function setBaseUrl(url) {
703
- axiosInstance.defaults.baseURL = url;
704
- }
705
- //------------------------------------------------------------------------------
706
- class ServiceError extends Error {
707
- errorCode;
708
- httpCode;
709
- message;
710
- //--------------------------------------------------------------------------
711
- constructor(errorCode, httpCode, message) {
712
- super();
713
- this.errorCode = errorCode;
714
- this.httpCode = httpCode;
715
- this.message = message;
716
- }
717
- }
718
- //------------------------------------------------------------------------------
719
- class ApiError extends ServiceError {
720
- serviceError;
721
- constructor(errorCode, status, message, serviceError) {
722
- super(errorCode, status, message);
723
- this.serviceError = serviceError;
724
- }
725
- }
726
- //------------------------------------------------------------------------------
727
- class UnexpectedServiceError extends ServiceError {
728
- unexpectedError;
729
- constructor(status, unexpectedError) {
730
- super(0, status, 'Unexpected service error error');
731
- this.unexpectedError = unexpectedError;
732
- }
733
- }
734
- //------------------------------------------------------------------------------
735
- function installInterceptors() {
736
- const CLIENT_ERROR = 400;
737
- const INTERNAL_SERVER_ERROR = 500;
738
- axiosInstance.interceptors.response.use(successFulResponse => {
739
- if (successFulResponse.config.responseType === 'stream') {
740
- successFulResponse.data.pause();
741
- }
742
- return successFulResponse;
743
- }, error => {
744
- if (!error.response) {
745
- return Promise.reject(error);
746
- }
747
- const axiosError = error;
748
- const status = axiosError.response?.status || INTERNAL_SERVER_ERROR;
749
- const errorData = axiosError.response?.data;
750
- if (!errorData &&
751
- axiosError.request.method === 'HEAD' &&
752
- status >= CLIENT_ERROR &&
753
- status < INTERNAL_SERVER_ERROR) {
754
- return axiosError.response;
755
- }
756
- if (!errorData || !('error' in errorData)) {
757
- return Promise.reject(new UnexpectedServiceError(status, errorData));
758
- }
759
- const serviceError = errorData.error;
760
- return Promise.reject(new ApiError(serviceError.errorCode, status, serviceError.message, serviceError));
761
- });
762
- }
763
- //------------------------------------------------------------------------------
691
+ //------------------------------------------------------------------------------
692
+ function setApiKey(apiKey) {
693
+ axiosInstance.defaults.headers.common['api_key'] = apiKey;
694
+ delete axiosInstance.defaults.headers.common['user_token'];
695
+ }
696
+ //------------------------------------------------------------------------------
697
+ function setUserToken(userToken) {
698
+ axiosInstance.defaults.headers.common['user_token'] = userToken;
699
+ delete axiosInstance.defaults.headers.common['api_key'];
700
+ }
701
+ //------------------------------------------------------------------------------
702
+ function setBaseUrl(url) {
703
+ axiosInstance.defaults.baseURL = url;
704
+ }
705
+ //------------------------------------------------------------------------------
706
+ class ServiceError extends Error {
707
+ errorCode;
708
+ httpCode;
709
+ message;
710
+ //--------------------------------------------------------------------------
711
+ constructor(errorCode, httpCode, message) {
712
+ super();
713
+ this.errorCode = errorCode;
714
+ this.httpCode = httpCode;
715
+ this.message = message;
716
+ }
717
+ }
718
+ //------------------------------------------------------------------------------
719
+ class ApiError extends ServiceError {
720
+ serviceError;
721
+ constructor(errorCode, status, message, serviceError) {
722
+ super(errorCode, status, message);
723
+ this.serviceError = serviceError;
724
+ }
725
+ }
726
+ //------------------------------------------------------------------------------
727
+ class UnexpectedServiceError extends ServiceError {
728
+ unexpectedError;
729
+ constructor(status, unexpectedError) {
730
+ super(0, status, 'Unexpected service error error');
731
+ this.unexpectedError = unexpectedError;
732
+ }
733
+ }
734
+ //------------------------------------------------------------------------------
735
+ function installInterceptors() {
736
+ const CLIENT_ERROR = 400;
737
+ const INTERNAL_SERVER_ERROR = 500;
738
+ axiosInstance.interceptors.response.use(successFulResponse => {
739
+ if (successFulResponse.config.responseType === 'stream') {
740
+ successFulResponse.data.pause();
741
+ }
742
+ return successFulResponse;
743
+ }, error => {
744
+ if (!error.response) {
745
+ return Promise.reject(error);
746
+ }
747
+ const axiosError = error;
748
+ const status = axiosError.response?.status || INTERNAL_SERVER_ERROR;
749
+ const errorData = axiosError.response?.data;
750
+ if (!errorData &&
751
+ axiosError.request.method === 'HEAD' &&
752
+ status >= CLIENT_ERROR &&
753
+ status < INTERNAL_SERVER_ERROR) {
754
+ return axiosError.response;
755
+ }
756
+ if (!errorData || !('error' in errorData)) {
757
+ return Promise.reject(new UnexpectedServiceError(status, errorData));
758
+ }
759
+ const serviceError = errorData.error;
760
+ return Promise.reject(new ApiError(serviceError.errorCode, status, serviceError.message, serviceError));
761
+ });
762
+ }
763
+ //------------------------------------------------------------------------------
764
764
  installInterceptors();
765
765
 
766
766
  exports.ApiError = ApiError;