@inweb/client 25.5.4 → 25.6.1

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/dist/client.js CHANGED
@@ -4,6 +4,125 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.ODA = global.ODA || {}, global.ODA.Api = global.ODA.Api || {})));
5
5
  })(this, (function (exports) { 'use strict';
6
6
 
7
+ ///////////////////////////////////////////////////////////////////////////////
8
+ // Copyright (C) 2002-2021, Open Design Alliance (the "Alliance").
9
+ // All rights reserved.
10
+ //
11
+ // This software and its documentation and related materials are owned by
12
+ // the Alliance. The software may only be incorporated into application
13
+ // programs owned by members of the Alliance, subject to a signed
14
+ // Membership Agreement and Supplemental Software License Agreement with the
15
+ // Alliance. The structure and organization of this software are the valuable
16
+ // trade secrets of the Alliance and its suppliers. The software is also
17
+ // protected by copyright law and international treaty provisions. Application
18
+ // programs incorporating this software must include the following statement
19
+ // with their copyright notices:
20
+ //
21
+ // This application incorporates Open Design Alliance software pursuant to a
22
+ // license agreement with Open Design Alliance.
23
+ // Open Design Alliance Copyright (C) 2002-2021 by Open Design Alliance.
24
+ // All rights reserved.
25
+ //
26
+ // By use of this software, its documentation or related materials, you
27
+ // acknowledge and accept the above terms.
28
+ ///////////////////////////////////////////////////////////////////////////////
29
+ const STATUS_CODES = {
30
+ 100: "Continue",
31
+ 101: "Switching Protocols",
32
+ 102: "Processing",
33
+ 103: "Early Hints",
34
+ 200: "OK",
35
+ 201: "Created",
36
+ 202: "Accepted",
37
+ 203: "Non-Authoritative Information",
38
+ 204: "No Content",
39
+ 205: "Reset Content",
40
+ 206: "Partial Content",
41
+ 207: "Multi-Status",
42
+ 208: "Already Reported",
43
+ 226: "IM Used",
44
+ 300: "Multiple Choices",
45
+ 301: "Moved Permanently",
46
+ 302: "Found",
47
+ 303: "See Other",
48
+ 304: "Not Modified",
49
+ 305: "Use Proxy",
50
+ 307: "Temporary Redirect",
51
+ 308: "Permanent Redirect",
52
+ 400: "Bad Request",
53
+ 401: "Unauthorized",
54
+ 402: "Payment Required",
55
+ 403: "Forbidden",
56
+ 404: "Not Found",
57
+ 405: "Method Not Allowed",
58
+ 406: "Not Acceptable",
59
+ 407: "Proxy Authentication Required",
60
+ 408: "Request Time-out",
61
+ 409: "Conflict",
62
+ 410: "Gone",
63
+ 411: "Length Required",
64
+ 412: "Precondition Failed",
65
+ 413: "Payload Too Large",
66
+ 414: "URI Too Long",
67
+ 415: "Unsupported Media Type",
68
+ 416: "Range Not Satisfiable",
69
+ 417: "Expectation Failed",
70
+ 418: "I'm a teapot",
71
+ 421: "Misdirected Request",
72
+ 422: "Unprocessable Entity",
73
+ 423: "Locked",
74
+ 424: "Failed Dependency",
75
+ 425: "Too Early",
76
+ 426: "Upgrade Required",
77
+ 428: "Precondition Required",
78
+ 429: "Too Many Requests",
79
+ 431: "Header Fields Too Large",
80
+ 451: "Unavailable For Legal Reasons",
81
+ 500: "Internal Server Error",
82
+ 501: "Not Implemented",
83
+ 502: "Bad Gateway",
84
+ 503: "Service Unavailable",
85
+ 504: "Gateway Timeout",
86
+ 505: "HTTP Version Not Supported",
87
+ 506: "Variant Also Negotiates",
88
+ 507: "Insufficient Storage",
89
+ 508: "Loop Detected",
90
+ 509: "Bandwidth Limit Exceeded",
91
+ 510: "Not Extended",
92
+ 511: "Network Authentication Required",
93
+ };
94
+ function statusText(status) {
95
+ return STATUS_CODES[status] || `Error ${status}`;
96
+ }
97
+ function error400(text, _default = "400") {
98
+ try {
99
+ return JSON.parse(text).description;
100
+ }
101
+ catch {
102
+ return _default;
103
+ }
104
+ }
105
+ /**
106
+ * The `FetchError` object indicates an error when request to Open Cloud Server could not be
107
+ * performed. A `FetchError` is typically (but not exclusively) thrown when a network error
108
+ * occurs, access denied, or object not found.
109
+ */
110
+ class FetchError extends Error {
111
+ /**
112
+ * @property status - The <a href="https://developer.mozilla.org/docs/Web/HTTP/Status" target
113
+ * ="_blank">HTTP status code</a> of the response.
114
+ * @property message - Error message. Inherited from <a
115
+ * href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error"
116
+ * target ="_blank">Error</a>.
117
+ */
118
+ constructor(status, message) {
119
+ super(message || statusText(status));
120
+ this.name = "FetchError";
121
+ this.status = status;
122
+ this.statusText = statusText(status);
123
+ }
124
+ }
125
+
7
126
  ///////////////////////////////////////////////////////////////////////////////
8
127
  // Copyright (C) 2002-2021, Open Design Alliance (the "Alliance").
9
128
  // All rights reserved.
@@ -597,125 +716,6 @@
597
716
  }
598
717
  }
599
718
 
600
- ///////////////////////////////////////////////////////////////////////////////
601
- // Copyright (C) 2002-2021, Open Design Alliance (the "Alliance").
602
- // All rights reserved.
603
- //
604
- // This software and its documentation and related materials are owned by
605
- // the Alliance. The software may only be incorporated into application
606
- // programs owned by members of the Alliance, subject to a signed
607
- // Membership Agreement and Supplemental Software License Agreement with the
608
- // Alliance. The structure and organization of this software are the valuable
609
- // trade secrets of the Alliance and its suppliers. The software is also
610
- // protected by copyright law and international treaty provisions. Application
611
- // programs incorporating this software must include the following statement
612
- // with their copyright notices:
613
- //
614
- // This application incorporates Open Design Alliance software pursuant to a
615
- // license agreement with Open Design Alliance.
616
- // Open Design Alliance Copyright (C) 2002-2021 by Open Design Alliance.
617
- // All rights reserved.
618
- //
619
- // By use of this software, its documentation or related materials, you
620
- // acknowledge and accept the above terms.
621
- ///////////////////////////////////////////////////////////////////////////////
622
- const STATUS_CODES = {
623
- 100: "Continue",
624
- 101: "Switching Protocols",
625
- 102: "Processing",
626
- 103: "Early Hints",
627
- 200: "OK",
628
- 201: "Created",
629
- 202: "Accepted",
630
- 203: "Non-Authoritative Information",
631
- 204: "No Content",
632
- 205: "Reset Content",
633
- 206: "Partial Content",
634
- 207: "Multi-Status",
635
- 208: "Already Reported",
636
- 226: "IM Used",
637
- 300: "Multiple Choices",
638
- 301: "Moved Permanently",
639
- 302: "Found",
640
- 303: "See Other",
641
- 304: "Not Modified",
642
- 305: "Use Proxy",
643
- 307: "Temporary Redirect",
644
- 308: "Permanent Redirect",
645
- 400: "Bad Request",
646
- 401: "Unauthorized",
647
- 402: "Payment Required",
648
- 403: "Forbidden",
649
- 404: "Not Found",
650
- 405: "Method Not Allowed",
651
- 406: "Not Acceptable",
652
- 407: "Proxy Authentication Required",
653
- 408: "Request Time-out",
654
- 409: "Conflict",
655
- 410: "Gone",
656
- 411: "Length Required",
657
- 412: "Precondition Failed",
658
- 413: "Payload Too Large",
659
- 414: "URI Too Long",
660
- 415: "Unsupported Media Type",
661
- 416: "Range Not Satisfiable",
662
- 417: "Expectation Failed",
663
- 418: "I'm a teapot",
664
- 421: "Misdirected Request",
665
- 422: "Unprocessable Entity",
666
- 423: "Locked",
667
- 424: "Failed Dependency",
668
- 425: "Too Early",
669
- 426: "Upgrade Required",
670
- 428: "Precondition Required",
671
- 429: "Too Many Requests",
672
- 431: "Header Fields Too Large",
673
- 451: "Unavailable For Legal Reasons",
674
- 500: "Internal Server Error",
675
- 501: "Not Implemented",
676
- 502: "Bad Gateway",
677
- 503: "Service Unavailable",
678
- 504: "Gateway Timeout",
679
- 505: "HTTP Version Not Supported",
680
- 506: "Variant Also Negotiates",
681
- 507: "Insufficient Storage",
682
- 508: "Loop Detected",
683
- 509: "Bandwidth Limit Exceeded",
684
- 510: "Not Extended",
685
- 511: "Network Authentication Required",
686
- };
687
- function statusText(status) {
688
- return STATUS_CODES[status] || `Error ${status}`;
689
- }
690
- function error400(text, _default = "400") {
691
- try {
692
- return JSON.parse(text).description;
693
- }
694
- catch {
695
- return _default;
696
- }
697
- }
698
- /**
699
- * The `FetchError` object indicates an error when request to Open Cloud Server could not be
700
- * performed. A `FetchError` is typically (but not exclusively) thrown when a network error
701
- * occurs, access denied, or object not found.
702
- */
703
- class FetchError extends Error {
704
- /**
705
- * @property status - The <a href="https://developer.mozilla.org/docs/Web/HTTP/Status" target
706
- * ="_blank">HTTP status code</a> of the response.
707
- * @property message - Error message. Inherited from <a
708
- * href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error"
709
- * target ="_blank">Error</a>.
710
- */
711
- constructor(status, message) {
712
- super(message || statusText(status));
713
- this.name = "FetchError";
714
- this.status = status;
715
- this.statusText = statusText(status);
716
- }
717
- }
718
-
719
719
  ///////////////////////////////////////////////////////////////////////////////
720
720
  /**
721
721
  * The class representing a `assembly` entity.
@@ -1420,6 +1420,7 @@
1420
1420
  constructor(serverUrl) {
1421
1421
  this.headers = {};
1422
1422
  this.signInUserId = "";
1423
+ this.signInUserIsAdmin = false;
1423
1424
  this.serverUrl = serverUrl;
1424
1425
  }
1425
1426
  get(relativePath, signal) {
@@ -3555,15 +3556,18 @@
3555
3556
  * administrator rights, hi can only checkout himself, otherwise an exception will be thrown.
3556
3557
  */
3557
3558
  async checkout() {
3558
- if (this.id === this.httpClient.signInUserId) {
3559
+ if (this.httpClient.signInUserIsAdmin) {
3560
+ const response = await this.httpClient.get(`/users/${this.id}`);
3561
+ const data = await response.json();
3562
+ this.data = { id: data.id, ...data.userBrief };
3563
+ }
3564
+ else if (this.id === this.httpClient.signInUserId) {
3559
3565
  const response = await this.httpClient.get("/user");
3560
3566
  const data = await response.json();
3561
3567
  this.data = { id: this.id, ...data };
3562
3568
  }
3563
3569
  else {
3564
- const response = await this.httpClient.get(`/users/${this.id}`);
3565
- const data = await response.json();
3566
- this.data = { id: data.id, ...data.userBrief };
3570
+ return Promise.reject(new FetchError(403));
3567
3571
  }
3568
3572
  return this;
3569
3573
  }
@@ -3577,15 +3581,18 @@
3577
3581
  * @param data - Raw user data.
3578
3582
  */
3579
3583
  async update(data) {
3580
- if (this.id === this.httpClient.signInUserId) {
3584
+ if (this.httpClient.signInUserIsAdmin) {
3585
+ const response = await this.httpClient.put(`/users/${this.id}`, { userBrief: data });
3586
+ const newData = await response.json();
3587
+ this.data = { id: newData.id, ...newData.userBrief };
3588
+ }
3589
+ else if (this.id === this.httpClient.signInUserId) {
3581
3590
  const response = await this.httpClient.put("/user", data);
3582
3591
  const newData = await response.json();
3583
3592
  this.data = { id: this.id, ...newData };
3584
3593
  }
3585
3594
  else {
3586
- const response = await this.httpClient.put(`/users/${this.id}`, { userBrief: data });
3587
- const newData = await response.json();
3588
- this.data = { id: newData.id, ...newData.userBrief };
3595
+ return Promise.reject(new FetchError(403));
3589
3596
  }
3590
3597
  return this;
3591
3598
  }
@@ -3604,16 +3611,22 @@
3604
3611
  * @returns Returns the raw data of a deleted user.
3605
3612
  */
3606
3613
  delete() {
3607
- return this.httpClient
3608
- .delete(`/users/${this.id}`)
3609
- .then((response) => response.json())
3610
- .then((data) => {
3611
- if (this.id === this.httpClient.signInUserId) {
3612
- this.httpClient.headers = {};
3613
- this.httpClient.signInUserId = "";
3614
- }
3615
- return data;
3616
- });
3614
+ if (this.httpClient.signInUserIsAdmin) {
3615
+ return this.httpClient
3616
+ .delete(`/users/${this.id}`)
3617
+ .then((response) => response.json())
3618
+ .then((data) => {
3619
+ if (this.id === this.httpClient.signInUserId) {
3620
+ this.httpClient.headers = {};
3621
+ this.httpClient.signInUserId = "";
3622
+ this.httpClient.signInUserIsAdmin = false;
3623
+ }
3624
+ return data;
3625
+ });
3626
+ }
3627
+ else {
3628
+ return Promise.reject(new FetchError(403));
3629
+ }
3617
3630
  }
3618
3631
  /**
3619
3632
  * Save user data changes to the server. Call this method to update user data on the server
@@ -3631,39 +3644,55 @@
3631
3644
  * administrator rights, he can only set his own avatar, otherwise an exception will be thrown.
3632
3645
  *
3633
3646
  * @async
3634
- * @param image - Avatar image. Can be a <a
3635
- * href="https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/Data_URIs"
3636
- * target="_blank">Data URL</a> string, <a
3637
- * href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer"
3638
- * target="_blank">ArrayBuffer</a>, <a
3639
- * href="https://developer.mozilla.org/docs/Web/API/Blob/Blob" target="_blank">Blob</a> or
3640
- * Web API <a href="https://developer.mozilla.org/docs/Web/API/File"
3641
- * target="_blank">File</a> object. Setting the `image` to `null` will remove the avatar.
3647
+ * @param image - Avatar image. Can be a
3648
+ * {@link https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/Data_URIs | Data URL}
3649
+ * string,
3650
+ * {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer | ArrayBuffer},
3651
+ * {@link https://developer.mozilla.org/docs/Web/API/Blob/Blob | Blob} or Web API
3652
+ * {@link https://developer.mozilla.org/docs/Web/API/File | File} object. Setting the
3653
+ * `image` to `null` will remove the avatar.
3642
3654
  */
3643
3655
  async setAvatar(image) {
3644
- if (image) {
3645
- if (this.id === this.httpClient.signInUserId) {
3646
- const response = await this.httpClient.post("/user/avatar", image);
3647
- const data = await response.json();
3648
- this.data = { id: this.id, ...data };
3649
- }
3650
- else {
3651
- const response = await this.httpClient.post(`/users/${this.id}/avatar`, image);
3652
- const data = await response.json();
3653
- this.data = { id: data.id, ...data.userBrief };
3654
- }
3656
+ if (!image) {
3657
+ await this.deleteAvatar();
3658
+ }
3659
+ else if (this.httpClient.signInUserIsAdmin) {
3660
+ const response = await this.httpClient.post(`/users/${this.id}/avatar`, image);
3661
+ const data = await response.json();
3662
+ this.data = { id: data.id, ...data.userBrief };
3663
+ }
3664
+ else if (this.id === this.httpClient.signInUserId) {
3665
+ const response = await this.httpClient.post("/user/avatar", image);
3666
+ const data = await response.json();
3667
+ this.data = { id: this.id, ...data };
3655
3668
  }
3656
3669
  else {
3657
- if (this.id === this.httpClient.signInUserId) {
3658
- const response = await this.httpClient.delete("/user/avatar");
3659
- const data = await response.json();
3660
- this.data = { id: this.id, ...data };
3661
- }
3662
- else {
3663
- const response = await this.httpClient.delete(`/users/${this.id}/avatar`);
3664
- const data = await response.json();
3665
- this.data = { id: data.id, ...data.userBrief };
3666
- }
3670
+ return Promise.reject(new FetchError(403));
3671
+ }
3672
+ return this;
3673
+ }
3674
+ /**
3675
+ * Remove the user avatar.
3676
+ *
3677
+ * Only admins can remove the avatar of other users, if the current logged in user does not
3678
+ * have administrator rights, they can only remove their own avatar, otherwise an exception
3679
+ * will be thrown.
3680
+ *
3681
+ * @async
3682
+ */
3683
+ async deleteAvatar() {
3684
+ if (this.httpClient.signInUserIsAdmin) {
3685
+ const response = await this.httpClient.delete(`/users/${this.id}/avatar`);
3686
+ const data = await response.json();
3687
+ this.data = { id: data.id, ...data.userBrief };
3688
+ }
3689
+ else if (this.id === this.httpClient.signInUserId) {
3690
+ const response = await this.httpClient.delete("/user/avatar");
3691
+ const data = await response.json();
3692
+ this.data = { id: this.id, ...data };
3693
+ }
3694
+ else {
3695
+ return Promise.reject(new FetchError(403));
3667
3696
  }
3668
3697
  return this;
3669
3698
  }
@@ -3768,7 +3797,7 @@
3768
3797
  .then((data) => ({
3769
3798
  ...data,
3770
3799
  server: data.version,
3771
- client: "25.5.4",
3800
+ client: "25.6.1",
3772
3801
  }));
3773
3802
  }
3774
3803
  /**
@@ -3845,12 +3874,14 @@
3845
3874
  this._user = new User(data, this.httpClient);
3846
3875
  this.httpClient.headers = { Authorization: data.tokenInfo.token };
3847
3876
  this.httpClient.signInUserId = this._user.id;
3877
+ this.httpClient.signInUserIsAdmin = this._user.isAdmin;
3848
3878
  return this._user;
3849
3879
  }
3850
3880
  clearCurrentUser() {
3851
3881
  this._user = null;
3852
3882
  this.httpClient.headers = {};
3853
3883
  this.httpClient.signInUserId = "";
3884
+ this.httpClient.signInUserIsAdmin = false;
3854
3885
  }
3855
3886
  /**
3856
3887
  * Returns the current logged in user information. Returns `null` if the user is not logged
@@ -3919,20 +3950,23 @@
3919
3950
  * @param userId - User ID.
3920
3951
  */
3921
3952
  getUser(userId) {
3922
- if (userId === this.httpClient.signInUserId) {
3953
+ if (this.httpClient.signInUserIsAdmin) {
3923
3954
  return this.httpClient
3924
- .get("/user")
3955
+ .get(`/users/${userId}`)
3925
3956
  .then((response) => response.json())
3926
- .then((data) => ({ id: userId, ...data }))
3957
+ .then((data) => ({ id: data.id, ...data.userBrief }))
3927
3958
  .then((data) => new User(data, this.httpClient));
3928
3959
  }
3929
- else {
3960
+ else if (userId === this.httpClient.signInUserId) {
3930
3961
  return this.httpClient
3931
- .get(`/users/${userId}`)
3962
+ .get("/user")
3932
3963
  .then((response) => response.json())
3933
- .then((data) => ({ id: data.id, ...data.userBrief }))
3964
+ .then((data) => ({ id: userId, ...data }))
3934
3965
  .then((data) => new User(data, this.httpClient));
3935
3966
  }
3967
+ else {
3968
+ return Promise.reject(new FetchError(403));
3969
+ }
3936
3970
  }
3937
3971
  /**
3938
3972
  * Create a new user.
@@ -3986,15 +4020,20 @@
3986
4020
  * @returns Returns the raw data of a deleted user.
3987
4021
  */
3988
4022
  deleteUser(userId) {
3989
- return this.httpClient
3990
- .delete(`/users/${userId}`)
3991
- .then((response) => response.json())
3992
- .then((data) => {
3993
- if (userId === this.httpClient.signInUserId) {
3994
- this.clearCurrentUser();
3995
- }
3996
- return data;
3997
- });
4023
+ if (this.httpClient.signInUserIsAdmin) {
4024
+ return this.httpClient
4025
+ .delete(`/users/${userId}`)
4026
+ .then((response) => response.json())
4027
+ .then((data) => {
4028
+ if (userId === this.httpClient.signInUserId) {
4029
+ this.clearCurrentUser();
4030
+ }
4031
+ return data;
4032
+ });
4033
+ }
4034
+ else {
4035
+ return Promise.reject(new FetchError(403));
4036
+ }
3998
4037
  }
3999
4038
  /**
4000
4039
  * Result for file list.
@@ -4447,9 +4486,8 @@
4447
4486
  * @param description - Project description.
4448
4487
  * @param startDate - Project start date.
4449
4488
  * @param endDate - Project end date.
4450
- * @param avatarUrl - Project preview image URL. Can be <a
4451
- * href="https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/Data_URIs"
4452
- * target="_blank">Data URL</a>.
4489
+ * @param avatarUrl - Project preview image URL. Can be
4490
+ * {@link https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/Data_URIs | Data URL}.
4453
4491
  */
4454
4492
  createProject(name, description, startDate, endDate, avatarUrl) {
4455
4493
  return this.httpClient
@@ -4487,7 +4525,7 @@
4487
4525
  }
4488
4526
 
4489
4527
  ///////////////////////////////////////////////////////////////////////////////
4490
- const version = "25.5.4";
4528
+ const version = "25.6.1";
4491
4529
 
4492
4530
  exports.Assembly = Assembly;
4493
4531
  exports.ClashTest = ClashTest;