@inweb/client 25.5.4 → 25.6.0

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.
@@ -1,3 +1,90 @@
1
+ const STATUS_CODES = {
2
+ 100: "Continue",
3
+ 101: "Switching Protocols",
4
+ 102: "Processing",
5
+ 103: "Early Hints",
6
+ 200: "OK",
7
+ 201: "Created",
8
+ 202: "Accepted",
9
+ 203: "Non-Authoritative Information",
10
+ 204: "No Content",
11
+ 205: "Reset Content",
12
+ 206: "Partial Content",
13
+ 207: "Multi-Status",
14
+ 208: "Already Reported",
15
+ 226: "IM Used",
16
+ 300: "Multiple Choices",
17
+ 301: "Moved Permanently",
18
+ 302: "Found",
19
+ 303: "See Other",
20
+ 304: "Not Modified",
21
+ 305: "Use Proxy",
22
+ 307: "Temporary Redirect",
23
+ 308: "Permanent Redirect",
24
+ 400: "Bad Request",
25
+ 401: "Unauthorized",
26
+ 402: "Payment Required",
27
+ 403: "Forbidden",
28
+ 404: "Not Found",
29
+ 405: "Method Not Allowed",
30
+ 406: "Not Acceptable",
31
+ 407: "Proxy Authentication Required",
32
+ 408: "Request Time-out",
33
+ 409: "Conflict",
34
+ 410: "Gone",
35
+ 411: "Length Required",
36
+ 412: "Precondition Failed",
37
+ 413: "Payload Too Large",
38
+ 414: "URI Too Long",
39
+ 415: "Unsupported Media Type",
40
+ 416: "Range Not Satisfiable",
41
+ 417: "Expectation Failed",
42
+ 418: "I'm a teapot",
43
+ 421: "Misdirected Request",
44
+ 422: "Unprocessable Entity",
45
+ 423: "Locked",
46
+ 424: "Failed Dependency",
47
+ 425: "Too Early",
48
+ 426: "Upgrade Required",
49
+ 428: "Precondition Required",
50
+ 429: "Too Many Requests",
51
+ 431: "Header Fields Too Large",
52
+ 451: "Unavailable For Legal Reasons",
53
+ 500: "Internal Server Error",
54
+ 501: "Not Implemented",
55
+ 502: "Bad Gateway",
56
+ 503: "Service Unavailable",
57
+ 504: "Gateway Timeout",
58
+ 505: "HTTP Version Not Supported",
59
+ 506: "Variant Also Negotiates",
60
+ 507: "Insufficient Storage",
61
+ 508: "Loop Detected",
62
+ 509: "Bandwidth Limit Exceeded",
63
+ 510: "Not Extended",
64
+ 511: "Network Authentication Required"
65
+ };
66
+
67
+ function statusText(status) {
68
+ return STATUS_CODES[status] || `Error ${status}`;
69
+ }
70
+
71
+ function error400(text, _default = "400") {
72
+ try {
73
+ return JSON.parse(text).description;
74
+ } catch {
75
+ return _default;
76
+ }
77
+ }
78
+
79
+ class FetchError extends Error {
80
+ constructor(status, message) {
81
+ super(message || statusText(status));
82
+ this.name = "FetchError";
83
+ this.status = status;
84
+ this.statusText = statusText(status);
85
+ }
86
+ }
87
+
1
88
  class Model {
2
89
  constructor(data, file) {
3
90
  this.path = `${file.path}/downloads`;
@@ -256,93 +343,6 @@ class ClashTest {
256
343
  }
257
344
  }
258
345
 
259
- const STATUS_CODES = {
260
- 100: "Continue",
261
- 101: "Switching Protocols",
262
- 102: "Processing",
263
- 103: "Early Hints",
264
- 200: "OK",
265
- 201: "Created",
266
- 202: "Accepted",
267
- 203: "Non-Authoritative Information",
268
- 204: "No Content",
269
- 205: "Reset Content",
270
- 206: "Partial Content",
271
- 207: "Multi-Status",
272
- 208: "Already Reported",
273
- 226: "IM Used",
274
- 300: "Multiple Choices",
275
- 301: "Moved Permanently",
276
- 302: "Found",
277
- 303: "See Other",
278
- 304: "Not Modified",
279
- 305: "Use Proxy",
280
- 307: "Temporary Redirect",
281
- 308: "Permanent Redirect",
282
- 400: "Bad Request",
283
- 401: "Unauthorized",
284
- 402: "Payment Required",
285
- 403: "Forbidden",
286
- 404: "Not Found",
287
- 405: "Method Not Allowed",
288
- 406: "Not Acceptable",
289
- 407: "Proxy Authentication Required",
290
- 408: "Request Time-out",
291
- 409: "Conflict",
292
- 410: "Gone",
293
- 411: "Length Required",
294
- 412: "Precondition Failed",
295
- 413: "Payload Too Large",
296
- 414: "URI Too Long",
297
- 415: "Unsupported Media Type",
298
- 416: "Range Not Satisfiable",
299
- 417: "Expectation Failed",
300
- 418: "I'm a teapot",
301
- 421: "Misdirected Request",
302
- 422: "Unprocessable Entity",
303
- 423: "Locked",
304
- 424: "Failed Dependency",
305
- 425: "Too Early",
306
- 426: "Upgrade Required",
307
- 428: "Precondition Required",
308
- 429: "Too Many Requests",
309
- 431: "Header Fields Too Large",
310
- 451: "Unavailable For Legal Reasons",
311
- 500: "Internal Server Error",
312
- 501: "Not Implemented",
313
- 502: "Bad Gateway",
314
- 503: "Service Unavailable",
315
- 504: "Gateway Timeout",
316
- 505: "HTTP Version Not Supported",
317
- 506: "Variant Also Negotiates",
318
- 507: "Insufficient Storage",
319
- 508: "Loop Detected",
320
- 509: "Bandwidth Limit Exceeded",
321
- 510: "Not Extended",
322
- 511: "Network Authentication Required"
323
- };
324
-
325
- function statusText(status) {
326
- return STATUS_CODES[status] || `Error ${status}`;
327
- }
328
-
329
- function error400(text, _default = "400") {
330
- try {
331
- return JSON.parse(text).description;
332
- } catch {
333
- return _default;
334
- }
335
- }
336
-
337
- class FetchError extends Error {
338
- constructor(status, message) {
339
- super(message || statusText(status));
340
- this.name = "FetchError";
341
- this.status = status;
342
- this.statusText = statusText(status);
343
- }
344
- }
345
-
346
346
  class Assembly {
347
347
  constructor(data, httpClient) {
348
348
  this.path = `/assemblies/${data.id}`;
@@ -734,6 +734,7 @@ class HttpClient {
734
734
  constructor(serverUrl) {
735
735
  this.headers = {};
736
736
  this.signInUserId = "";
737
+ this.signInUserIsAdmin = false;
737
738
  this.serverUrl = serverUrl;
738
739
  }
739
740
  get(relativePath, signal) {
@@ -1684,7 +1685,14 @@ class User {
1684
1685
  this._data.userName = value;
1685
1686
  }
1686
1687
  async checkout() {
1687
- if (this.id === this.httpClient.signInUserId) {
1688
+ if (this.httpClient.signInUserIsAdmin) {
1689
+ const response = await this.httpClient.get(`/users/${this.id}`);
1690
+ const data = await response.json();
1691
+ this.data = {
1692
+ id: data.id,
1693
+ ...data.userBrief
1694
+ };
1695
+ } else if (this.id === this.httpClient.signInUserId) {
1688
1696
  const response = await this.httpClient.get("/user");
1689
1697
  const data = await response.json();
1690
1698
  this.data = {
@@ -1692,24 +1700,12 @@ class User {
1692
1700
  ...data
1693
1701
  };
1694
1702
  } else {
1695
- const response = await this.httpClient.get(`/users/${this.id}`);
1696
- const data = await response.json();
1697
- this.data = {
1698
- id: data.id,
1699
- ...data.userBrief
1700
- };
1703
+ return Promise.reject(new FetchError(403));
1701
1704
  }
1702
1705
  return this;
1703
1706
  }
1704
1707
  async update(data) {
1705
- if (this.id === this.httpClient.signInUserId) {
1706
- const response = await this.httpClient.put("/user", data);
1707
- const newData = await response.json();
1708
- this.data = {
1709
- id: this.id,
1710
- ...newData
1711
- };
1712
- } else {
1708
+ if (this.httpClient.signInUserIsAdmin) {
1713
1709
  const response = await this.httpClient.put(`/users/${this.id}`, {
1714
1710
  userBrief: data
1715
1711
  });
@@ -1718,54 +1714,74 @@ class User {
1718
1714
  id: newData.id,
1719
1715
  ...newData.userBrief
1720
1716
  };
1717
+ } else if (this.id === this.httpClient.signInUserId) {
1718
+ const response = await this.httpClient.put("/user", data);
1719
+ const newData = await response.json();
1720
+ this.data = {
1721
+ id: this.id,
1722
+ ...newData
1723
+ };
1724
+ } else {
1725
+ return Promise.reject(new FetchError(403));
1721
1726
  }
1722
1727
  return this;
1723
1728
  }
1724
1729
  delete() {
1725
- return this.httpClient.delete(`/users/${this.id}`).then((response => response.json())).then((data => {
1726
- if (this.id === this.httpClient.signInUserId) {
1727
- this.httpClient.headers = {};
1728
- this.httpClient.signInUserId = "";
1729
- }
1730
- return data;
1731
- }));
1730
+ if (this.httpClient.signInUserIsAdmin) {
1731
+ return this.httpClient.delete(`/users/${this.id}`).then((response => response.json())).then((data => {
1732
+ if (this.id === this.httpClient.signInUserId) {
1733
+ this.httpClient.headers = {};
1734
+ this.httpClient.signInUserId = "";
1735
+ this.httpClient.signInUserIsAdmin = false;
1736
+ }
1737
+ return data;
1738
+ }));
1739
+ } else {
1740
+ return Promise.reject(new FetchError(403));
1741
+ }
1732
1742
  }
1733
1743
  save() {
1734
1744
  return this.update(this.data);
1735
1745
  }
1736
1746
  async setAvatar(image) {
1737
- if (image) {
1738
- if (this.id === this.httpClient.signInUserId) {
1739
- const response = await this.httpClient.post("/user/avatar", image);
1740
- const data = await response.json();
1741
- this.data = {
1742
- id: this.id,
1743
- ...data
1744
- };
1745
- } else {
1746
- const response = await this.httpClient.post(`/users/${this.id}/avatar`, image);
1747
- const data = await response.json();
1748
- this.data = {
1749
- id: data.id,
1750
- ...data.userBrief
1751
- };
1752
- }
1747
+ if (!image) {
1748
+ await this.deleteAvatar();
1749
+ } else if (this.httpClient.signInUserIsAdmin) {
1750
+ const response = await this.httpClient.post(`/users/${this.id}/avatar`, image);
1751
+ const data = await response.json();
1752
+ this.data = {
1753
+ id: data.id,
1754
+ ...data.userBrief
1755
+ };
1756
+ } else if (this.id === this.httpClient.signInUserId) {
1757
+ const response = await this.httpClient.post("/user/avatar", image);
1758
+ const data = await response.json();
1759
+ this.data = {
1760
+ id: this.id,
1761
+ ...data
1762
+ };
1753
1763
  } else {
1754
- if (this.id === this.httpClient.signInUserId) {
1755
- const response = await this.httpClient.delete("/user/avatar");
1756
- const data = await response.json();
1757
- this.data = {
1758
- id: this.id,
1759
- ...data
1760
- };
1761
- } else {
1762
- const response = await this.httpClient.delete(`/users/${this.id}/avatar`);
1763
- const data = await response.json();
1764
- this.data = {
1765
- id: data.id,
1766
- ...data.userBrief
1767
- };
1768
- }
1764
+ return Promise.reject(new FetchError(403));
1765
+ }
1766
+ return this;
1767
+ }
1768
+ async deleteAvatar() {
1769
+ if (this.httpClient.signInUserIsAdmin) {
1770
+ const response = await this.httpClient.delete(`/users/${this.id}/avatar`);
1771
+ const data = await response.json();
1772
+ this.data = {
1773
+ id: data.id,
1774
+ ...data.userBrief
1775
+ };
1776
+ } else if (this.id === this.httpClient.signInUserId) {
1777
+ const response = await this.httpClient.delete("/user/avatar");
1778
+ const data = await response.json();
1779
+ this.data = {
1780
+ id: this.id,
1781
+ ...data
1782
+ };
1783
+ } else {
1784
+ return Promise.reject(new FetchError(403));
1769
1785
  }
1770
1786
  return this;
1771
1787
  }
@@ -1842,7 +1858,7 @@ class Client extends EventEmitter2 {
1842
1858
  return this.httpClient.get("/version").then((response => response.json())).then((data => ({
1843
1859
  ...data,
1844
1860
  server: data.version,
1845
- client: "25.5.4"
1861
+ client: "25.6.0"
1846
1862
  })));
1847
1863
  }
1848
1864
  registerUser(email, password, userName) {
@@ -1884,12 +1900,14 @@ class Client extends EventEmitter2 {
1884
1900
  Authorization: data.tokenInfo.token
1885
1901
  };
1886
1902
  this.httpClient.signInUserId = this._user.id;
1903
+ this.httpClient.signInUserIsAdmin = this._user.isAdmin;
1887
1904
  return this._user;
1888
1905
  }
1889
1906
  clearCurrentUser() {
1890
1907
  this._user = null;
1891
1908
  this.httpClient.headers = {};
1892
1909
  this.httpClient.signInUserId = "";
1910
+ this.httpClient.signInUserIsAdmin = false;
1893
1911
  }
1894
1912
  getCurrentUser() {
1895
1913
  if (this._user && !this.httpClient.signInUserId) this._user = null;
@@ -1911,16 +1929,18 @@ class Client extends EventEmitter2 {
1911
1929
  }))))).then((array => array.map((data => new User(data, this.httpClient)))));
1912
1930
  }
1913
1931
  getUser(userId) {
1914
- if (userId === this.httpClient.signInUserId) {
1932
+ if (this.httpClient.signInUserIsAdmin) {
1933
+ return this.httpClient.get(`/users/${userId}`).then((response => response.json())).then((data => ({
1934
+ id: data.id,
1935
+ ...data.userBrief
1936
+ }))).then((data => new User(data, this.httpClient)));
1937
+ } else if (userId === this.httpClient.signInUserId) {
1915
1938
  return this.httpClient.get("/user").then((response => response.json())).then((data => ({
1916
1939
  id: userId,
1917
1940
  ...data
1918
1941
  }))).then((data => new User(data, this.httpClient)));
1919
1942
  } else {
1920
- return this.httpClient.get(`/users/${userId}`).then((response => response.json())).then((data => ({
1921
- id: data.id,
1922
- ...data.userBrief
1923
- }))).then((data => new User(data, this.httpClient)));
1943
+ return Promise.reject(new FetchError(403));
1924
1944
  }
1925
1945
  }
1926
1946
  createUser(email, password, params = {}) {
@@ -1939,12 +1959,16 @@ class Client extends EventEmitter2 {
1939
1959
  }))).then((data => new User(data, this.httpClient)));
1940
1960
  }
1941
1961
  deleteUser(userId) {
1942
- return this.httpClient.delete(`/users/${userId}`).then((response => response.json())).then((data => {
1943
- if (userId === this.httpClient.signInUserId) {
1944
- this.clearCurrentUser();
1945
- }
1946
- return data;
1947
- }));
1962
+ if (this.httpClient.signInUserIsAdmin) {
1963
+ return this.httpClient.delete(`/users/${userId}`).then((response => response.json())).then((data => {
1964
+ if (userId === this.httpClient.signInUserId) {
1965
+ this.clearCurrentUser();
1966
+ }
1967
+ return data;
1968
+ }));
1969
+ } else {
1970
+ return Promise.reject(new FetchError(403));
1971
+ }
1948
1972
  }
1949
1973
  getFiles(start, limit, name, ext, ids, sortByDesc, sortField) {
1950
1974
  const searchParams = new URLSearchParams;
@@ -2123,7 +2147,7 @@ class Client extends EventEmitter2 {
2123
2147
  }
2124
2148
  }
2125
2149
 
2126
- const version = "25.5.4";
2150
+ const version = "25.6.0";
2127
2151
 
2128
2152
  export { Assembly, ClashTest, Client, FetchError, File, Job, Member, Model, Permission, Project, Role, User, parseArgs, statusText, userFullName, userInitials, version, waitFor };
2129
2153
  //# sourceMappingURL=client.module.js.map