@inweb/client 25.4.11 → 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,92 +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.status = status;
341
- this.statusText = statusText(status);
342
- }
343
- }
344
-
345
346
  class Assembly {
346
347
  constructor(data, httpClient) {
347
348
  this.path = `/assemblies/${data.id}`;
@@ -733,6 +734,7 @@ class HttpClient {
733
734
  constructor(serverUrl) {
734
735
  this.headers = {};
735
736
  this.signInUserId = "";
737
+ this.signInUserIsAdmin = false;
736
738
  this.serverUrl = serverUrl;
737
739
  }
738
740
  get(relativePath, signal) {
@@ -1670,6 +1672,9 @@ class User {
1670
1672
  get projectsLimit() {
1671
1673
  return this.data.projectsLimit;
1672
1674
  }
1675
+ get providerType() {
1676
+ return this.data.providerType;
1677
+ }
1673
1678
  get token() {
1674
1679
  return this.data.tokenInfo.token;
1675
1680
  }
@@ -1680,7 +1685,14 @@ class User {
1680
1685
  this._data.userName = value;
1681
1686
  }
1682
1687
  async checkout() {
1683
- 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) {
1684
1696
  const response = await this.httpClient.get("/user");
1685
1697
  const data = await response.json();
1686
1698
  this.data = {
@@ -1688,24 +1700,12 @@ class User {
1688
1700
  ...data
1689
1701
  };
1690
1702
  } else {
1691
- const response = await this.httpClient.get(`/users/${this.id}`);
1692
- const data = await response.json();
1693
- this.data = {
1694
- id: data.id,
1695
- ...data.userBrief
1696
- };
1703
+ return Promise.reject(new FetchError(403));
1697
1704
  }
1698
1705
  return this;
1699
1706
  }
1700
1707
  async update(data) {
1701
- if (this.id === this.httpClient.signInUserId) {
1702
- const response = await this.httpClient.put("/user", data);
1703
- const newData = await response.json();
1704
- this.data = {
1705
- id: this.id,
1706
- ...newData
1707
- };
1708
- } else {
1708
+ if (this.httpClient.signInUserIsAdmin) {
1709
1709
  const response = await this.httpClient.put(`/users/${this.id}`, {
1710
1710
  userBrief: data
1711
1711
  });
@@ -1714,54 +1714,74 @@ class User {
1714
1714
  id: newData.id,
1715
1715
  ...newData.userBrief
1716
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));
1717
1726
  }
1718
1727
  return this;
1719
1728
  }
1720
1729
  delete() {
1721
- return this.httpClient.delete(`/users/${this.id}`).then((response => response.json())).then((data => {
1722
- if (this.id === this.httpClient.signInUserId) {
1723
- this.httpClient.headers = {};
1724
- this.httpClient.signInUserId = "";
1725
- }
1726
- return data;
1727
- }));
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
+ }
1728
1742
  }
1729
1743
  save() {
1730
1744
  return this.update(this.data);
1731
1745
  }
1732
1746
  async setAvatar(image) {
1733
- if (image) {
1734
- if (this.id === this.httpClient.signInUserId) {
1735
- const response = await this.httpClient.post("/user/avatar", image);
1736
- const data = await response.json();
1737
- this.data = {
1738
- id: this.id,
1739
- ...data
1740
- };
1741
- } else {
1742
- const response = await this.httpClient.post(`/users/${this.id}/avatar`, image);
1743
- const data = await response.json();
1744
- this.data = {
1745
- id: data.id,
1746
- ...data.userBrief
1747
- };
1748
- }
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
+ };
1749
1763
  } else {
1750
- if (this.id === this.httpClient.signInUserId) {
1751
- const response = await this.httpClient.delete("/user/avatar");
1752
- const data = await response.json();
1753
- this.data = {
1754
- id: this.id,
1755
- ...data
1756
- };
1757
- } else {
1758
- const response = await this.httpClient.delete(`/users/${this.id}/avatar`);
1759
- const data = await response.json();
1760
- this.data = {
1761
- id: data.id,
1762
- ...data.userBrief
1763
- };
1764
- }
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));
1765
1785
  }
1766
1786
  return this;
1767
1787
  }
@@ -1838,7 +1858,7 @@ class Client extends EventEmitter2 {
1838
1858
  return this.httpClient.get("/version").then((response => response.json())).then((data => ({
1839
1859
  ...data,
1840
1860
  server: data.version,
1841
- client: "25.4.11"
1861
+ client: "25.6.0"
1842
1862
  })));
1843
1863
  }
1844
1864
  registerUser(email, password, userName) {
@@ -1874,26 +1894,34 @@ class Client extends EventEmitter2 {
1874
1894
  const data = await response.json();
1875
1895
  return this.setCurrentUser(data);
1876
1896
  }
1877
- getIdentityProviders() {
1878
- return this.httpClient.get("/identity").then((response => response.json()));
1879
- }
1880
1897
  setCurrentUser(data) {
1881
1898
  this._user = new User(data, this.httpClient);
1882
1899
  this.httpClient.headers = {
1883
1900
  Authorization: data.tokenInfo.token
1884
1901
  };
1885
1902
  this.httpClient.signInUserId = this._user.id;
1903
+ this.httpClient.signInUserIsAdmin = this._user.isAdmin;
1886
1904
  return this._user;
1887
1905
  }
1888
1906
  clearCurrentUser() {
1889
1907
  this._user = null;
1890
1908
  this.httpClient.headers = {};
1891
1909
  this.httpClient.signInUserId = "";
1910
+ this.httpClient.signInUserIsAdmin = false;
1892
1911
  }
1893
1912
  getCurrentUser() {
1894
1913
  if (this._user && !this.httpClient.signInUserId) this._user = null;
1895
1914
  return this._user;
1896
1915
  }
1916
+ getIdentityProviders() {
1917
+ return this.httpClient.get("/identity").then((response => response.json()));
1918
+ }
1919
+ getServerSettings() {
1920
+ return this.httpClient.get("/settings").then((response => response.json()));
1921
+ }
1922
+ updateServerSettings(settings) {
1923
+ return this.httpClient.put("/settings", settings).then((response => response.json()));
1924
+ }
1897
1925
  getUsers() {
1898
1926
  return this.httpClient.get("/users").then((response => response.json())).then((array => array.map((data => ({
1899
1927
  id: data.id,
@@ -1901,16 +1929,18 @@ class Client extends EventEmitter2 {
1901
1929
  }))))).then((array => array.map((data => new User(data, this.httpClient)))));
1902
1930
  }
1903
1931
  getUser(userId) {
1904
- 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) {
1905
1938
  return this.httpClient.get("/user").then((response => response.json())).then((data => ({
1906
1939
  id: userId,
1907
1940
  ...data
1908
1941
  }))).then((data => new User(data, this.httpClient)));
1909
1942
  } else {
1910
- return this.httpClient.get(`/users/${userId}`).then((response => response.json())).then((data => ({
1911
- id: data.id,
1912
- ...data.userBrief
1913
- }))).then((data => new User(data, this.httpClient)));
1943
+ return Promise.reject(new FetchError(403));
1914
1944
  }
1915
1945
  }
1916
1946
  createUser(email, password, params = {}) {
@@ -1929,12 +1959,16 @@ class Client extends EventEmitter2 {
1929
1959
  }))).then((data => new User(data, this.httpClient)));
1930
1960
  }
1931
1961
  deleteUser(userId) {
1932
- return this.httpClient.delete(`/users/${userId}`).then((response => response.json())).then((data => {
1933
- if (userId === this.httpClient.signInUserId) {
1934
- this.clearCurrentUser();
1935
- }
1936
- return data;
1937
- }));
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
+ }
1938
1972
  }
1939
1973
  getFiles(start, limit, name, ext, ids, sortByDesc, sortField) {
1940
1974
  const searchParams = new URLSearchParams;
@@ -2113,7 +2147,7 @@ class Client extends EventEmitter2 {
2113
2147
  }
2114
2148
  }
2115
2149
 
2116
- const version = "25.4.11";
2150
+ const version = "25.6.0";
2117
2151
 
2118
2152
  export { Assembly, ClashTest, Client, FetchError, File, Job, Member, Model, Permission, Project, Role, User, parseArgs, statusText, userFullName, userInitials, version, waitFor };
2119
2153
  //# sourceMappingURL=client.module.js.map