@devtable/settings-form 5.8.0 → 5.8.2

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.
@@ -2,6 +2,6 @@ import { DataSourceType, IDataSource, IDataSourceConfig } from './datasource.typ
2
2
  import { PaginationResponse } from './types';
3
3
  export declare const datasource: {
4
4
  list: () => Promise<PaginationResponse<IDataSource>>;
5
- create: (type: DataSourceType, key: string, config: IDataSourceConfig) => Promise<PaginationResponse<IDataSource> | false>;
5
+ create: (type: DataSourceType, key: string, config: IDataSourceConfig) => Promise<PaginationResponse<IDataSource>>;
6
6
  delete: (id: string) => Promise<void>;
7
7
  };
@@ -1,7 +1,7 @@
1
1
  export declare const APICaller: {
2
2
  datasource: {
3
3
  list: () => Promise<import("./types").PaginationResponse<import("./datasource.typed").IDataSource>>;
4
- create: (type: import("./datasource.typed").DataSourceType, key: string, config: import("./datasource.typed").IDataSourceConfig) => Promise<false | import("./types").PaginationResponse<import("./datasource.typed").IDataSource>>;
4
+ create: (type: import("./datasource.typed").DataSourceType, key: string, config: import("./datasource.typed").IDataSourceConfig) => Promise<import("./types").PaginationResponse<import("./datasource.typed").IDataSource>>;
5
5
  delete: (id: string) => Promise<void>;
6
6
  };
7
7
  account: {
@@ -5,9 +5,10 @@ import { useForm as ee, Controller as E } from "react-hook-form";
5
5
  import { PlaylistAdd as Ee, Trash as Ce, Edit as Wr } from "tabler-icons-react";
6
6
  import Vr from "axios";
7
7
  import Yr from "crypto-js";
8
+ import Kr from "lodash";
8
9
  import { useRequest as G } from "ahooks";
9
- import { useModals as le, closeAllModals as Kr } from "@mantine/modals";
10
- function Br(t) {
10
+ import { useModals as le, closeAllModals as Br } from "@mantine/modals";
11
+ function Gr(t) {
11
12
  t = t || {};
12
13
  const n = Object.keys(t).sort(), o = [];
13
14
  for (let s = 0; s < n.length; s++) {
@@ -26,8 +27,8 @@ function Br(t) {
26
27
  }
27
28
  return o.sort().join("&");
28
29
  }
29
- function Gr(t, n) {
30
- let o = Br(t);
30
+ function Jr(t, n) {
31
+ let o = Gr(t);
31
32
  return o += "&key=" + n, Yr.MD5(o).toString().toUpperCase();
32
33
  }
33
34
  const C = {
@@ -41,7 +42,7 @@ const C = {
41
42
  return {
42
43
  app_id: this.app_id,
43
44
  nonce_str: n,
44
- sign: Gr(
45
+ sign: Jr(
45
46
  {
46
47
  app_id: this.app_id,
47
48
  nonce_str: n,
@@ -65,14 +66,14 @@ const C = {
65
66
  params: t === "GET" ? o : s.params,
66
67
  headers: i
67
68
  };
68
- return ["POST", "PUT"].includes(t) && (u.data = s.string ? JSON.stringify(o) : o, u.data.authentication = this.getAuthentication(u.data)), Vr(u).then((d) => d.data).catch((d) => Promise.reject(d));
69
+ return ["POST", "PUT"].includes(t) && (u.data = s.string ? JSON.stringify(o) : o, u.data.authentication = this.getAuthentication(u.data)), Vr(u).then((d) => d.data).catch((d) => Kr.has(d, "response.data.detail.message") ? Promise.reject(new Error(d.response.data.detail.message)) : Promise.reject(d));
69
70
  };
70
71
  }
71
72
  };
72
73
  function ue(t) {
73
74
  C.baseURL !== t.apiBaseURL && (C.baseURL = t.apiBaseURL), t.app_id && (C.app_id = t.app_id), t.app_secret && (C.app_secret = t.app_secret);
74
75
  }
75
- const Jr = {
76
+ const Hr = {
76
77
  login: async (t, n) => {
77
78
  const o = {
78
79
  name: t,
@@ -119,7 +120,7 @@ const Jr = {
119
120
  if (!!t)
120
121
  return C.getRequest("POST")("/account/delete", { id: t });
121
122
  }
122
- }, Hr = {
123
+ }, Xr = {
123
124
  list: async () => await C.getRequest("POST")("/api/key/list", {
124
125
  filter: {
125
126
  search: ""
@@ -141,7 +142,7 @@ const Jr = {
141
142
  if (!!t)
142
143
  return C.getRequest("POST")("/api/key/delete", { id: t });
143
144
  }
144
- }, Xr = {
145
+ }, Qr = {
145
146
  list: async () => await C.getRequest("POST")("/datasource/list", {
146
147
  filter: {},
147
148
  sort: {
@@ -153,23 +154,17 @@ const Jr = {
153
154
  pagesize: 100
154
155
  }
155
156
  }),
156
- create: async (t, n, o) => {
157
- try {
158
- return await C.getRequest("POST")("/datasource/create", { type: t, key: n, config: o });
159
- } catch (s) {
160
- return console.error(s), !1;
161
- }
162
- },
157
+ create: async (t, n, o) => C.getRequest("POST")("/datasource/create", { type: t, key: n, config: o }),
163
158
  delete: async (t) => {
164
159
  await C.getRequest("POST")("/datasource/delete", { id: t });
165
160
  }
166
- }, Qr = {
161
+ }, Zr = {
167
162
  list: async () => await C.getRequest("GET")("/role/list", {})
168
163
  }, k = {
169
- datasource: Xr,
170
- account: Jr,
171
- role: Qr,
172
- api_key: Hr
164
+ datasource: Qr,
165
+ account: Hr,
166
+ role: Zr,
167
+ api_key: Xr
173
168
  }, de = {
174
169
  size: "sm",
175
170
  spacing: "md",
@@ -188,7 +183,7 @@ var fe = { exports: {} }, Q = {};
188
183
  * LICENSE file in the root directory of this source tree.
189
184
  */
190
185
  var Qe;
191
- function Zr() {
186
+ function et() {
192
187
  if (Qe)
193
188
  return Q;
194
189
  Qe = 1;
@@ -216,7 +211,7 @@ var Z = {};
216
211
  * LICENSE file in the root directory of this source tree.
217
212
  */
218
213
  var Ze;
219
- function et() {
214
+ function rt() {
220
215
  return Ze || (Ze = 1, process.env.NODE_ENV !== "production" && function() {
221
216
  var t = J, n = Symbol.for("react.element"), o = Symbol.for("react.portal"), s = Symbol.for("react.fragment"), l = Symbol.for("react.strict_mode"), i = Symbol.for("react.profiler"), u = Symbol.for("react.provider"), d = Symbol.for("react.context"), g = Symbol.for("react.forward_ref"), y = Symbol.for("react.suspense"), _ = Symbol.for("react.suspense_list"), v = Symbol.for("react.memo"), f = Symbol.for("react.lazy"), O = Symbol.for("react.offscreen"), M = Symbol.iterator, V = "@@iterator";
222
217
  function ge(e) {
@@ -794,10 +789,10 @@ Check the top-level render call using <` + c + ">.");
794
789
  }()), Z;
795
790
  }
796
791
  (function(t) {
797
- process.env.NODE_ENV === "production" ? t.exports = Zr() : t.exports = et();
792
+ process.env.NODE_ENV === "production" ? t.exports = et() : t.exports = rt();
798
793
  })(fe);
799
794
  const U = fe.exports.Fragment, r = fe.exports.jsx, w = fe.exports.jsxs;
800
- function rt({
795
+ function tt({
801
796
  postSubmit: t,
802
797
  styles: n = de
803
798
  }) {
@@ -825,26 +820,27 @@ function rt({
825
820
  key: u,
826
821
  config: d
827
822
  }) => {
828
- if ($({
823
+ $({
829
824
  id: "for-creating",
830
825
  title: "Pending",
831
826
  message: "Adding data source...",
832
827
  loading: !0
833
- }), !await k.datasource.create(i, u, d)) {
828
+ });
829
+ try {
830
+ await k.datasource.create(i, u, d), A({
831
+ id: "for-creating",
832
+ title: "Successful",
833
+ message: "Data source is added",
834
+ color: "green"
835
+ }), t();
836
+ } catch (g) {
834
837
  A({
835
838
  id: "for-creating",
836
839
  title: "Failed",
837
- message: "Test connection failed with given info",
840
+ message: g.message,
838
841
  color: "red"
839
842
  });
840
- return;
841
843
  }
842
- A({
843
- id: "for-creating",
844
- title: "Successful",
845
- message: "Data source is added",
846
- color: "green"
847
- }), t();
848
844
  }),
849
845
  children: [/* @__PURE__ */ r(E, {
850
846
  name: "type",
@@ -966,7 +962,7 @@ function rt({
966
962
  })
967
963
  });
968
964
  }
969
- function tt({
965
+ function nt({
970
966
  onSuccess: t,
971
967
  styles: n = de
972
968
  }) {
@@ -981,7 +977,7 @@ function tt({
981
977
  onDragStart: (d) => {
982
978
  d.stopPropagation();
983
979
  },
984
- children: /* @__PURE__ */ r(rt, {
980
+ children: /* @__PURE__ */ r(tt, {
985
981
  postSubmit: () => {
986
982
  t(), i();
987
983
  },
@@ -997,7 +993,7 @@ function tt({
997
993
  })]
998
994
  });
999
995
  }
1000
- function nt(t, n) {
996
+ function at(t, n) {
1001
997
  if (t == null)
1002
998
  return {};
1003
999
  var o = {}, s = Object.keys(t), l, i;
@@ -1005,10 +1001,10 @@ function nt(t, n) {
1005
1001
  l = s[i], !(n.indexOf(l) >= 0) && (o[l] = t[l]);
1006
1002
  return o;
1007
1003
  }
1008
- function at(t, n) {
1004
+ function it(t, n) {
1009
1005
  if (t == null)
1010
1006
  return {};
1011
- var o = nt(t, n), s, l;
1007
+ var o = at(t, n), s, l;
1012
1008
  if (Object.getOwnPropertySymbols) {
1013
1009
  var i = Object.getOwnPropertySymbols(t);
1014
1010
  for (l = 0; l < i.length; l++)
@@ -1016,12 +1012,12 @@ function at(t, n) {
1016
1012
  }
1017
1013
  return o;
1018
1014
  }
1019
- var it = ["size", "color", "stroke"];
1020
- function ot(t) {
1021
- var n = t.size, o = n === void 0 ? 24 : n, s = t.color, l = s === void 0 ? "currentColor" : s, i = t.stroke, u = i === void 0 ? 2 : i, d = at(t, it);
1015
+ var ot = ["size", "color", "stroke"];
1016
+ function st(t) {
1017
+ var n = t.size, o = n === void 0 ? 24 : n, s = t.color, l = s === void 0 ? "currentColor" : s, i = t.stroke, u = i === void 0 ? 2 : i, d = it(t, ot);
1022
1018
  return /* @__PURE__ */ w("svg", { xmlns: "http://www.w3.org/2000/svg", className: "icon icon-tabler icon-tabler-lock", width: o, height: o, viewBox: "0 0 24 24", strokeWidth: u, stroke: l, fill: "none", strokeLinecap: "round", strokeLinejoin: "round", ...d, children: [/* @__PURE__ */ r("path", { stroke: "none", d: "M0 0h24v24H0z", fill: "none" }), /* @__PURE__ */ r("rect", { x: 5, y: 11, width: 14, height: 10, rx: 2 }), /* @__PURE__ */ r("circle", { cx: 12, cy: 16, r: 1 }), /* @__PURE__ */ r("path", { d: "M8 11v-4a4 4 0 0 1 8 0v4" })] });
1023
1019
  }
1024
- function st({
1020
+ function ct({
1025
1021
  id: t,
1026
1022
  name: n,
1027
1023
  isProtected: o,
@@ -1062,7 +1058,7 @@ function st({
1062
1058
  },
1063
1059
  label: "This is a preset datasource, it can not be deleted",
1064
1060
  children: /* @__PURE__ */ r("span", {
1065
- children: /* @__PURE__ */ r(ot, {
1061
+ children: /* @__PURE__ */ r(st, {
1066
1062
  size: 16,
1067
1063
  color: g.colors.gray[7]
1068
1064
  })
@@ -1077,7 +1073,7 @@ function st({
1077
1073
  children: "Delete"
1078
1074
  });
1079
1075
  }
1080
- function Tt({
1076
+ function At({
1081
1077
  styles: t = de,
1082
1078
  config: n
1083
1079
  }) {
@@ -1098,7 +1094,7 @@ function Tt({
1098
1094
  children: [/* @__PURE__ */ r(I, {
1099
1095
  pt: t.spacing,
1100
1096
  position: "right",
1101
- children: /* @__PURE__ */ r(tt, {
1097
+ children: /* @__PURE__ */ r(nt, {
1102
1098
  onSuccess: l
1103
1099
  })
1104
1100
  }), /* @__PURE__ */ w(L, {
@@ -1139,7 +1135,7 @@ function Tt({
1139
1135
  width: 200,
1140
1136
  children: /* @__PURE__ */ r(I, {
1141
1137
  position: "left",
1142
- children: /* @__PURE__ */ r(st, {
1138
+ children: /* @__PURE__ */ r(ct, {
1143
1139
  isProtected: g,
1144
1140
  id: i,
1145
1141
  name: u,
@@ -1153,7 +1149,7 @@ function Tt({
1153
1149
  })]
1154
1150
  });
1155
1151
  }
1156
- const ct = tr(({
1152
+ const lt = tr(({
1157
1153
  label: t,
1158
1154
  value: n,
1159
1155
  description: o,
@@ -1193,7 +1189,7 @@ const ct = tr(({
1193
1189
  size: t.size,
1194
1190
  required: !0,
1195
1191
  label: "Role",
1196
- itemComponent: ct,
1192
+ itemComponent: lt,
1197
1193
  data: l,
1198
1194
  disabled: i,
1199
1195
  styles: () => ({
@@ -1217,7 +1213,7 @@ const ct = tr(({
1217
1213
  size: "xs"
1218
1214
  }
1219
1215
  };
1220
- function lt({
1216
+ function ut({
1221
1217
  postSubmit: t,
1222
1218
  styles: n = W,
1223
1219
  initialRoleID: o
@@ -1321,7 +1317,7 @@ function lt({
1321
1317
  })
1322
1318
  });
1323
1319
  }
1324
- function ut({
1320
+ function dt({
1325
1321
  onSuccess: t,
1326
1322
  styles: n = W,
1327
1323
  initialRoleID: o
@@ -1337,7 +1333,7 @@ function ut({
1337
1333
  onDragStart: (g) => {
1338
1334
  g.stopPropagation();
1339
1335
  },
1340
- children: /* @__PURE__ */ r(lt, {
1336
+ children: /* @__PURE__ */ r(ut, {
1341
1337
  postSubmit: () => {
1342
1338
  t(), u();
1343
1339
  },
@@ -1354,7 +1350,7 @@ function ut({
1354
1350
  })]
1355
1351
  });
1356
1352
  }
1357
- function dt({
1353
+ function ft({
1358
1354
  id: t,
1359
1355
  name: n,
1360
1356
  onSuccess: o,
@@ -1403,7 +1399,7 @@ function dt({
1403
1399
  children: "Delete"
1404
1400
  });
1405
1401
  }
1406
- function ft({
1402
+ function pt({
1407
1403
  id: t,
1408
1404
  name: n,
1409
1405
  email: o,
@@ -1543,7 +1539,7 @@ function ft({
1543
1539
  })
1544
1540
  });
1545
1541
  }
1546
- function pt({
1542
+ function gt({
1547
1543
  account: t,
1548
1544
  onSuccess: n,
1549
1545
  styles: o = W
@@ -1561,7 +1557,7 @@ function pt({
1561
1557
  onDragStart: (g) => {
1562
1558
  g.stopPropagation();
1563
1559
  },
1564
- children: /* @__PURE__ */ r(ft, {
1560
+ children: /* @__PURE__ */ r(pt, {
1565
1561
  ...t,
1566
1562
  postSubmit: d,
1567
1563
  styles: o
@@ -1576,7 +1572,7 @@ function pt({
1576
1572
  })]
1577
1573
  });
1578
1574
  }
1579
- function zt({
1575
+ function Ot({
1580
1576
  styles: t = W,
1581
1577
  config: n
1582
1578
  }) {
@@ -1611,7 +1607,7 @@ function zt({
1611
1607
  children: [/* @__PURE__ */ r(I, {
1612
1608
  pt: t.spacing,
1613
1609
  position: "right",
1614
- children: /* @__PURE__ */ r(ut, {
1610
+ children: /* @__PURE__ */ r(dt, {
1615
1611
  onSuccess: l,
1616
1612
  initialRoleID: (_ = (y = i == null ? void 0 : i[0]) == null ? void 0 : y.value) != null ? _ : 0
1617
1613
  })
@@ -1661,10 +1657,10 @@ function zt({
1661
1657
  width: 200,
1662
1658
  children: /* @__PURE__ */ w(I, {
1663
1659
  position: "left",
1664
- children: [/* @__PURE__ */ r(pt, {
1660
+ children: [/* @__PURE__ */ r(gt, {
1665
1661
  account: v,
1666
1662
  onSuccess: l
1667
- }), /* @__PURE__ */ r(dt, {
1663
+ }), /* @__PURE__ */ r(ft, {
1668
1664
  id: f,
1669
1665
  name: O,
1670
1666
  onSuccess: l
@@ -1678,7 +1674,7 @@ function zt({
1678
1674
  })]
1679
1675
  });
1680
1676
  }
1681
- function gt({
1677
+ function ht({
1682
1678
  postSubmit: t,
1683
1679
  styles: n = W
1684
1680
  }) {
@@ -1757,7 +1753,7 @@ function gt({
1757
1753
  })
1758
1754
  });
1759
1755
  }
1760
- function At({
1756
+ function kt({
1761
1757
  styles: t = W,
1762
1758
  config: n,
1763
1759
  onSuccess: o
@@ -1768,7 +1764,7 @@ function At({
1768
1764
  sx: {
1769
1765
  position: "relative"
1770
1766
  },
1771
- children: /* @__PURE__ */ r(gt, {
1767
+ children: /* @__PURE__ */ r(ht, {
1772
1768
  styles: t,
1773
1769
  postSubmit: o
1774
1770
  })
@@ -1782,7 +1778,7 @@ const pe = {
1782
1778
  size: "xs"
1783
1779
  }
1784
1780
  };
1785
- function ht({
1781
+ function mt({
1786
1782
  postSubmit: t,
1787
1783
  styles: n = pe,
1788
1784
  initialRoleID: o
@@ -1862,7 +1858,7 @@ function ht({
1862
1858
  })
1863
1859
  });
1864
1860
  }
1865
- function mt({
1861
+ function vt({
1866
1862
  onSuccess: t,
1867
1863
  styles: n = pe,
1868
1864
  initialRoleID: o
@@ -1878,7 +1874,7 @@ function mt({
1878
1874
  onDragStart: (y) => {
1879
1875
  y.stopPropagation();
1880
1876
  },
1881
- children: /* @__PURE__ */ r(ht, {
1877
+ children: /* @__PURE__ */ r(mt, {
1882
1878
  postSubmit: (y, _) => {
1883
1879
  d(), s.openModal({
1884
1880
  title: "API Key is generated",
@@ -1907,7 +1903,7 @@ function mt({
1907
1903
  }), /* @__PURE__ */ r(x, {
1908
1904
  size: "sm",
1909
1905
  onClick: () => {
1910
- Kr();
1906
+ Br();
1911
1907
  },
1912
1908
  children: "I've saved this API Key"
1913
1909
  })]
@@ -1930,7 +1926,7 @@ function mt({
1930
1926
  })]
1931
1927
  });
1932
1928
  }
1933
- function vt({
1929
+ function bt({
1934
1930
  id: t,
1935
1931
  name: n,
1936
1932
  onSuccess: o,
@@ -1979,7 +1975,7 @@ function vt({
1979
1975
  children: "Delete"
1980
1976
  });
1981
1977
  }
1982
- function Ot({
1978
+ function xt({
1983
1979
  styles: t = pe,
1984
1980
  config: n
1985
1981
  }) {
@@ -2014,7 +2010,7 @@ function Ot({
2014
2010
  children: [/* @__PURE__ */ r(I, {
2015
2011
  pt: t.spacing,
2016
2012
  position: "right",
2017
- children: /* @__PURE__ */ r(mt, {
2013
+ children: /* @__PURE__ */ r(vt, {
2018
2014
  onSuccess: l,
2019
2015
  initialRoleID: (_ = (y = i == null ? void 0 : i[0]) == null ? void 0 : y.value) != null ? _ : 0
2020
2016
  })
@@ -2064,7 +2060,7 @@ function Ot({
2064
2060
  width: 200,
2065
2061
  children: /* @__PURE__ */ r(I, {
2066
2062
  position: "left",
2067
- children: /* @__PURE__ */ r(vt, {
2063
+ children: /* @__PURE__ */ r(bt, {
2068
2064
  id: f,
2069
2065
  name: O,
2070
2066
  onSuccess: l
@@ -2079,14 +2075,14 @@ function Ot({
2079
2075
  });
2080
2076
  }
2081
2077
  export {
2082
- Ot as APIKeyList,
2083
- zt as AccountList,
2084
- mt as AddAPIKey,
2085
- ut as AddAccount,
2086
- tt as AddDataSource,
2087
- Tt as DataSourceList,
2088
- vt as DeleteAPIKey,
2089
- dt as DeleteAccount,
2090
- st as DeleteDataSource,
2091
- At as Login
2078
+ xt as APIKeyList,
2079
+ Ot as AccountList,
2080
+ vt as AddAPIKey,
2081
+ dt as AddAccount,
2082
+ nt as AddDataSource,
2083
+ At as DataSourceList,
2084
+ bt as DeleteAPIKey,
2085
+ ft as DeleteAccount,
2086
+ ct as DeleteDataSource,
2087
+ kt as Login
2092
2088
  };
@@ -1,4 +1,4 @@
1
- (function(R,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@mantine/core"),require("@mantine/notifications"),require("react"),require("react-hook-form"),require("tabler-icons-react"),require("axios"),require("crypto-js"),require("ahooks"),require("@mantine/modals")):typeof define=="function"&&define.amd?define(["exports","@mantine/core","@mantine/notifications","react","react-hook-form","tabler-icons-react","axios","crypto-js","ahooks","@mantine/modals"],o):(R=typeof globalThis<"u"?globalThis:R||self,o(R["settings-form"]={},R["@mantine/core"],R["@mantine/notifications"],R.React,R["react-hook-form"],R["tabler-icons-react"],R.axios,R["crypto-js"],R.ahooks,R["@mantine/modals"]))})(this,function(R,o,C,K,S,F,Ze,He,W,J){"use strict";const ue=r=>r&&typeof r=="object"&&"default"in r?r:{default:r},V=ue(K),et=ue(Ze),tt=ue(He);function rt(r){r=r||{};const n=Object.keys(r).sort(),s=[];for(let l=0;l<n.length;l++){const u=n[l];if(u!="authentication"&&r[u])s.push(n[l]+"="+(typeof r[u]=="object"?JSON.stringify(r[u]):r[u]));else{const a=Object.keys(r[u]).sort();for(let d=0;d<a.length;d++){const f=a[d];f!="sign"&&r[u][f]&&s.push(a[d]+"="+(typeof r[u][f]=="object"?JSON.stringify(r[u][f]):r[u][f]))}}}return s.sort().join("&")}function nt(r,n){let s=rt(r);return s+="&key="+n,tt.default.MD5(s).toString().toUpperCase()}const x={baseURL:"http://localhost:31200",app_id:"",app_secret:"",getAuthentication(r){if(!this.app_id||!this.app_secret)return;const n=new Date().getTime().toString();return{app_id:this.app_id,nonce_str:n,sign:nt({app_id:this.app_id,nonce_str:n,...r},this.app_secret)}},getRequest(r){return(n,s,l={})=>{const u=window.localStorage.getItem("token"),a={"X-Requested-With":"XMLHttpRequest","Content-Type":l.string?"application/x-www-form-urlencoded":"application/json",authorization:u?`bearer ${u}`:"",...l.headers},d={baseURL:this.baseURL,method:r,url:n,params:r==="GET"?s:l.params,headers:a};return["POST","PUT"].includes(r)&&(d.data=l.string?JSON.stringify(s):s,d.data.authentication=this.getAuthentication(d.data)),et.default(d).then(f=>f.data).catch(f=>Promise.reject(f))}}};function ee(r){x.baseURL!==r.apiBaseURL&&(x.baseURL=r.apiBaseURL),r.app_id&&(x.app_id=r.app_id),r.app_secret&&(x.app_secret=r.app_secret)}const D={datasource:{list:async()=>await x.getRequest("POST")("/datasource/list",{filter:{},sort:{field:"create_time",order:"ASC"},pagination:{page:1,pagesize:100}}),create:async(r,n,s)=>{try{return await x.getRequest("POST")("/datasource/create",{type:r,key:n,config:s})}catch(l){return console.error(l),!1}},delete:async r=>{await x.getRequest("POST")("/datasource/delete",{id:r})}},account:{login:async(r,n)=>{const s={name:r,password:n};return await x.getRequest("POST")("/account/login",s)},list:async()=>await x.getRequest("POST")("/account/list",{filter:{search:""},sort:{field:"name",order:"ASC"},pagination:{page:1,pagesize:100}}),get:async()=>await x.getRequest("GET")("/account/get",{}),update:async(r,n)=>{const s={name:r,email:n};return await x.getRequest("PUT")("/account/update",s)},changepassword:async(r,n)=>{const s={old_password:r,new_password:n};return await x.getRequest("POST")("/account/changepassword",s)},create:async(r,n,s,l)=>await x.getRequest("POST")("/account/create",{name:r,email:n,password:s,role_id:l}),edit:async r=>(r.reset_password||(r.new_password=void 0),await x.getRequest("PUT")("/account/edit",r)),delete:async r=>{if(!!r)return x.getRequest("POST")("/account/delete",{id:r})}},role:{list:async()=>await x.getRequest("GET")("/role/list",{})},api_key:{list:async()=>await x.getRequest("POST")("/api/key/list",{filter:{search:""},sort:{field:"name",order:"ASC"},pagination:{page:1,pagesize:100}}),create:async(r,n)=>x.getRequest("POST")("/api/key/create",{name:r,role_id:n}),delete:async r=>{if(!!r)return x.getRequest("POST")("/api/key/delete",{id:r})}}},te={size:"sm",spacing:"md",button:{size:"xs"}};var re={exports:{}},X={};/**
1
+ (function(S,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@mantine/core"),require("@mantine/notifications"),require("react"),require("react-hook-form"),require("tabler-icons-react"),require("axios"),require("crypto-js"),require("lodash"),require("ahooks"),require("@mantine/modals")):typeof define=="function"&&define.amd?define(["exports","@mantine/core","@mantine/notifications","react","react-hook-form","tabler-icons-react","axios","crypto-js","lodash","ahooks","@mantine/modals"],o):(S=typeof globalThis<"u"?globalThis:S||self,o(S["settings-form"]={},S["@mantine/core"],S["@mantine/notifications"],S.React,S["react-hook-form"],S["tabler-icons-react"],S.axios,S["crypto-js"],S._,S.ahooks,S["@mantine/modals"]))})(this,function(S,o,C,K,P,F,Ze,He,et,W,J){"use strict";const ee=r=>r&&typeof r=="object"&&"default"in r?r:{default:r},V=ee(K),tt=ee(Ze),rt=ee(He),nt=ee(et);function at(r){r=r||{};const n=Object.keys(r).sort(),s=[];for(let l=0;l<n.length;l++){const u=n[l];if(u!="authentication"&&r[u])s.push(n[l]+"="+(typeof r[u]=="object"?JSON.stringify(r[u]):r[u]));else{const i=Object.keys(r[u]).sort();for(let d=0;d<i.length;d++){const f=i[d];f!="sign"&&r[u][f]&&s.push(i[d]+"="+(typeof r[u][f]=="object"?JSON.stringify(r[u][f]):r[u][f]))}}}return s.sort().join("&")}function it(r,n){let s=at(r);return s+="&key="+n,rt.default.MD5(s).toString().toUpperCase()}const x={baseURL:"http://localhost:31200",app_id:"",app_secret:"",getAuthentication(r){if(!this.app_id||!this.app_secret)return;const n=new Date().getTime().toString();return{app_id:this.app_id,nonce_str:n,sign:it({app_id:this.app_id,nonce_str:n,...r},this.app_secret)}},getRequest(r){return(n,s,l={})=>{const u=window.localStorage.getItem("token"),i={"X-Requested-With":"XMLHttpRequest","Content-Type":l.string?"application/x-www-form-urlencoded":"application/json",authorization:u?`bearer ${u}`:"",...l.headers},d={baseURL:this.baseURL,method:r,url:n,params:r==="GET"?s:l.params,headers:i};return["POST","PUT"].includes(r)&&(d.data=l.string?JSON.stringify(s):s,d.data.authentication=this.getAuthentication(d.data)),tt.default(d).then(f=>f.data).catch(f=>nt.default.has(f,"response.data.detail.message")?Promise.reject(new Error(f.response.data.detail.message)):Promise.reject(f))}}};function te(r){x.baseURL!==r.apiBaseURL&&(x.baseURL=r.apiBaseURL),r.app_id&&(x.app_id=r.app_id),r.app_secret&&(x.app_secret=r.app_secret)}const D={datasource:{list:async()=>await x.getRequest("POST")("/datasource/list",{filter:{},sort:{field:"create_time",order:"ASC"},pagination:{page:1,pagesize:100}}),create:async(r,n,s)=>x.getRequest("POST")("/datasource/create",{type:r,key:n,config:s}),delete:async r=>{await x.getRequest("POST")("/datasource/delete",{id:r})}},account:{login:async(r,n)=>{const s={name:r,password:n};return await x.getRequest("POST")("/account/login",s)},list:async()=>await x.getRequest("POST")("/account/list",{filter:{search:""},sort:{field:"name",order:"ASC"},pagination:{page:1,pagesize:100}}),get:async()=>await x.getRequest("GET")("/account/get",{}),update:async(r,n)=>{const s={name:r,email:n};return await x.getRequest("PUT")("/account/update",s)},changepassword:async(r,n)=>{const s={old_password:r,new_password:n};return await x.getRequest("POST")("/account/changepassword",s)},create:async(r,n,s,l)=>await x.getRequest("POST")("/account/create",{name:r,email:n,password:s,role_id:l}),edit:async r=>(r.reset_password||(r.new_password=void 0),await x.getRequest("PUT")("/account/edit",r)),delete:async r=>{if(!!r)return x.getRequest("POST")("/account/delete",{id:r})}},role:{list:async()=>await x.getRequest("GET")("/role/list",{})},api_key:{list:async()=>await x.getRequest("POST")("/api/key/list",{filter:{search:""},sort:{field:"name",order:"ASC"},pagination:{page:1,pagesize:100}}),create:async(r,n)=>x.getRequest("POST")("/api/key/create",{name:r,role_id:n}),delete:async r=>{if(!!r)return x.getRequest("POST")("/api/key/delete",{id:r})}}},re={size:"sm",spacing:"md",button:{size:"xs"}};var ne={exports:{}},X={};/**
2
2
  * @license React
3
3
  * react-jsx-runtime.production.min.js
4
4
  *
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * This source code is licensed under the MIT license found in the
8
8
  * LICENSE file in the root directory of this source tree.
9
- */var ye;function it(){if(ye)return X;ye=1;var r=V.default,n=Symbol.for("react.element"),s=Symbol.for("react.fragment"),l=Object.prototype.hasOwnProperty,u=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,a={key:!0,ref:!0,__self:!0,__source:!0};function d(f,h,T){var P,b={},p=null,j=null;T!==void 0&&(p=""+T),h.key!==void 0&&(p=""+h.key),h.ref!==void 0&&(j=h.ref);for(P in h)l.call(h,P)&&!a.hasOwnProperty(P)&&(b[P]=h[P]);if(f&&f.defaultProps)for(P in h=f.defaultProps,h)b[P]===void 0&&(b[P]=h[P]);return{$$typeof:n,type:f,key:p,ref:j,props:b,_owner:u.current}}return X.Fragment=s,X.jsx=d,X.jsxs=d,X}var Q={};/**
9
+ */var _e;function ot(){if(_e)return X;_e=1;var r=V.default,n=Symbol.for("react.element"),s=Symbol.for("react.fragment"),l=Object.prototype.hasOwnProperty,u=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,i={key:!0,ref:!0,__self:!0,__source:!0};function d(f,h,T){var R,b={},p=null,j=null;T!==void 0&&(p=""+T),h.key!==void 0&&(p=""+h.key),h.ref!==void 0&&(j=h.ref);for(R in h)l.call(h,R)&&!i.hasOwnProperty(R)&&(b[R]=h[R]);if(f&&f.defaultProps)for(R in h=f.defaultProps,h)b[R]===void 0&&(b[R]=h[R]);return{$$typeof:n,type:f,key:p,ref:j,props:b,_owner:u.current}}return X.Fragment=s,X.jsx=d,X.jsxs=d,X}var Q={};/**
10
10
  * @license React
11
11
  * react-jsx-runtime.development.js
12
12
  *
@@ -14,14 +14,14 @@
14
14
  *
15
15
  * This source code is licensed under the MIT license found in the
16
16
  * LICENSE file in the root directory of this source tree.
17
- */var _e;function at(){return _e||(_e=1,process.env.NODE_ENV!=="production"&&function(){var r=V.default,n=Symbol.for("react.element"),s=Symbol.for("react.portal"),l=Symbol.for("react.fragment"),u=Symbol.for("react.strict_mode"),a=Symbol.for("react.profiler"),d=Symbol.for("react.provider"),f=Symbol.for("react.context"),h=Symbol.for("react.forward_ref"),T=Symbol.for("react.suspense"),P=Symbol.for("react.suspense_list"),b=Symbol.for("react.memo"),p=Symbol.for("react.lazy"),j=Symbol.for("react.offscreen"),M=Symbol.iterator,B="@@iterator";function de(e){if(e===null||typeof e!="object")return null;var i=M&&e[M]||e[B];return typeof i=="function"?i:null}var $=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function z(e){{for(var i=arguments.length,c=new Array(i>1?i-1:0),g=1;g<i;g++)c[g-1]=arguments[g];_t("error",e,c)}}function _t(e,i,c){{var g=$.ReactDebugCurrentFrame,w=g.getStackAddendum();w!==""&&(i+="%s",c=c.concat([w]));var _=c.map(function(v){return String(v)});_.unshift("Warning: "+i),Function.prototype.apply.call(console[e],console,_)}}var St=!1,Pt=!1,Rt=!1,Ct=!1,Tt=!1,Ae;Ae=Symbol.for("react.module.reference");function Et(e){return!!(typeof e=="string"||typeof e=="function"||e===l||e===a||Tt||e===u||e===T||e===P||Ct||e===j||St||Pt||Rt||typeof e=="object"&&e!==null&&(e.$$typeof===p||e.$$typeof===b||e.$$typeof===d||e.$$typeof===f||e.$$typeof===h||e.$$typeof===Ae||e.getModuleId!==void 0))}function At(e,i,c){var g=e.displayName;if(g)return g;var w=i.displayName||i.name||"";return w!==""?c+"("+w+")":c}function xe(e){return e.displayName||"Context"}function k(e){if(e==null)return null;if(typeof e.tag=="number"&&z("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case l:return"Fragment";case s:return"Portal";case a:return"Profiler";case u:return"StrictMode";case T:return"Suspense";case P:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case f:var i=e;return xe(i)+".Consumer";case d:var c=e;return xe(c._context)+".Provider";case h:return At(e,e.render,"ForwardRef");case b:var g=e.displayName||null;return g!==null?g:k(e.type)||"Memo";case p:{var w=e,_=w._payload,v=w._init;try{return k(v(_))}catch{return null}}}return null}var U=Object.assign,Z=0,ze,Oe,De,je,Ie,ke,qe;function Ne(){}Ne.__reactDisabledLog=!0;function xt(){{if(Z===0){ze=console.log,Oe=console.info,De=console.warn,je=console.error,Ie=console.group,ke=console.groupCollapsed,qe=console.groupEnd;var e={configurable:!0,enumerable:!0,value:Ne,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}Z++}}function zt(){{if(Z--,Z===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:U({},e,{value:ze}),info:U({},e,{value:Oe}),warn:U({},e,{value:De}),error:U({},e,{value:je}),group:U({},e,{value:Ie}),groupCollapsed:U({},e,{value:ke}),groupEnd:U({},e,{value:qe})})}Z<0&&z("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var fe=$.ReactCurrentDispatcher,pe;function ie(e,i,c){{if(pe===void 0)try{throw Error()}catch(w){var g=w.stack.trim().match(/\n( *(at )?)/);pe=g&&g[1]||""}return`
18
- `+pe+e}}var ge=!1,ae;{var Ot=typeof WeakMap=="function"?WeakMap:Map;ae=new Ot}function Le(e,i){if(!e||ge)return"";{var c=ae.get(e);if(c!==void 0)return c}var g;ge=!0;var w=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var _;_=fe.current,fe.current=null,xt();try{if(i){var v=function(){throw Error()};if(Object.defineProperty(v.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(v,[])}catch(q){g=q}Reflect.construct(e,[],v)}else{try{v.call()}catch(q){g=q}e.call(v.prototype)}}else{try{throw Error()}catch(q){g=q}e()}}catch(q){if(q&&g&&typeof q.stack=="string"){for(var m=q.stack.split(`
17
+ */var ye;function st(){return ye||(ye=1,process.env.NODE_ENV!=="production"&&function(){var r=V.default,n=Symbol.for("react.element"),s=Symbol.for("react.portal"),l=Symbol.for("react.fragment"),u=Symbol.for("react.strict_mode"),i=Symbol.for("react.profiler"),d=Symbol.for("react.provider"),f=Symbol.for("react.context"),h=Symbol.for("react.forward_ref"),T=Symbol.for("react.suspense"),R=Symbol.for("react.suspense_list"),b=Symbol.for("react.memo"),p=Symbol.for("react.lazy"),j=Symbol.for("react.offscreen"),M=Symbol.iterator,B="@@iterator";function de(e){if(e===null||typeof e!="object")return null;var a=M&&e[M]||e[B];return typeof a=="function"?a:null}var $=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function z(e){{for(var a=arguments.length,c=new Array(a>1?a-1:0),g=1;g<a;g++)c[g-1]=arguments[g];Pt("error",e,c)}}function Pt(e,a,c){{var g=$.ReactDebugCurrentFrame,w=g.getStackAddendum();w!==""&&(a+="%s",c=c.concat([w]));var y=c.map(function(v){return String(v)});y.unshift("Warning: "+a),Function.prototype.apply.call(console[e],console,y)}}var Rt=!1,Ct=!1,Tt=!1,Et=!1,At=!1,Ae;Ae=Symbol.for("react.module.reference");function xt(e){return!!(typeof e=="string"||typeof e=="function"||e===l||e===i||At||e===u||e===T||e===R||Et||e===j||Rt||Ct||Tt||typeof e=="object"&&e!==null&&(e.$$typeof===p||e.$$typeof===b||e.$$typeof===d||e.$$typeof===f||e.$$typeof===h||e.$$typeof===Ae||e.getModuleId!==void 0))}function zt(e,a,c){var g=e.displayName;if(g)return g;var w=a.displayName||a.name||"";return w!==""?c+"("+w+")":c}function xe(e){return e.displayName||"Context"}function k(e){if(e==null)return null;if(typeof e.tag=="number"&&z("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case l:return"Fragment";case s:return"Portal";case i:return"Profiler";case u:return"StrictMode";case T:return"Suspense";case R:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case f:var a=e;return xe(a)+".Consumer";case d:var c=e;return xe(c._context)+".Provider";case h:return zt(e,e.render,"ForwardRef");case b:var g=e.displayName||null;return g!==null?g:k(e.type)||"Memo";case p:{var w=e,y=w._payload,v=w._init;try{return k(v(y))}catch{return null}}}return null}var U=Object.assign,Z=0,ze,Oe,De,je,Ie,ke,qe;function Ne(){}Ne.__reactDisabledLog=!0;function Ot(){{if(Z===0){ze=console.log,Oe=console.info,De=console.warn,je=console.error,Ie=console.group,ke=console.groupCollapsed,qe=console.groupEnd;var e={configurable:!0,enumerable:!0,value:Ne,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}Z++}}function Dt(){{if(Z--,Z===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:U({},e,{value:ze}),info:U({},e,{value:Oe}),warn:U({},e,{value:De}),error:U({},e,{value:je}),group:U({},e,{value:Ie}),groupCollapsed:U({},e,{value:ke}),groupEnd:U({},e,{value:qe})})}Z<0&&z("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var fe=$.ReactCurrentDispatcher,pe;function ie(e,a,c){{if(pe===void 0)try{throw Error()}catch(w){var g=w.stack.trim().match(/\n( *(at )?)/);pe=g&&g[1]||""}return`
18
+ `+pe+e}}var ge=!1,oe;{var jt=typeof WeakMap=="function"?WeakMap:Map;oe=new jt}function Le(e,a){if(!e||ge)return"";{var c=oe.get(e);if(c!==void 0)return c}var g;ge=!0;var w=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var y;y=fe.current,fe.current=null,Ot();try{if(a){var v=function(){throw Error()};if(Object.defineProperty(v.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(v,[])}catch(q){g=q}Reflect.construct(e,[],v)}else{try{v.call()}catch(q){g=q}e.call(v.prototype)}}else{try{throw Error()}catch(q){g=q}e()}}catch(q){if(q&&g&&typeof q.stack=="string"){for(var m=q.stack.split(`
19
19
  `),O=g.stack.split(`
20
20
  `),E=m.length-1,A=O.length-1;E>=1&&A>=0&&m[E]!==O[A];)A--;for(;E>=1&&A>=0;E--,A--)if(m[E]!==O[A]){if(E!==1||A!==1)do if(E--,A--,A<0||m[E]!==O[A]){var I=`
21
- `+m[E].replace(" at new "," at ");return e.displayName&&I.includes("<anonymous>")&&(I=I.replace("<anonymous>",e.displayName)),typeof e=="function"&&ae.set(e,I),I}while(E>=1&&A>=0);break}}}finally{ge=!1,fe.current=_,zt(),Error.prepareStackTrace=w}var G=e?e.displayName||e.name:"",Qe=G?ie(G):"";return typeof e=="function"&&ae.set(e,Qe),Qe}function Dt(e,i,c){return Le(e,!1)}function jt(e){var i=e.prototype;return!!(i&&i.isReactComponent)}function oe(e,i,c){if(e==null)return"";if(typeof e=="function")return Le(e,jt(e));if(typeof e=="string")return ie(e);switch(e){case T:return ie("Suspense");case P:return ie("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case h:return Dt(e.render);case b:return oe(e.type,i,c);case p:{var g=e,w=g._payload,_=g._init;try{return oe(_(w),i,c)}catch{}}}return""}var se=Object.prototype.hasOwnProperty,Me={},$e=$.ReactDebugCurrentFrame;function le(e){if(e){var i=e._owner,c=oe(e.type,e._source,i?i.type:null);$e.setExtraStackFrame(c)}else $e.setExtraStackFrame(null)}function It(e,i,c,g,w){{var _=Function.call.bind(se);for(var v in e)if(_(e,v)){var m=void 0;try{if(typeof e[v]!="function"){var O=Error((g||"React class")+": "+c+" type `"+v+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[v]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw O.name="Invariant Violation",O}m=e[v](i,v,g,c,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(E){m=E}m&&!(m instanceof Error)&&(le(w),z("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",g||"React class",c,v,typeof m),le(null)),m instanceof Error&&!(m.message in Me)&&(Me[m.message]=!0,le(w),z("Failed %s type: %s",c,m.message),le(null))}}}var kt=Array.isArray;function he(e){return kt(e)}function qt(e){{var i=typeof Symbol=="function"&&Symbol.toStringTag,c=i&&e[Symbol.toStringTag]||e.constructor.name||"Object";return c}}function Nt(e){try{return Fe(e),!1}catch{return!0}}function Fe(e){return""+e}function Be(e){if(Nt(e))return z("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",qt(e)),Fe(e)}var H=$.ReactCurrentOwner,Lt={key:!0,ref:!0,__self:!0,__source:!0},Ue,We,me;me={};function Mt(e){if(se.call(e,"ref")){var i=Object.getOwnPropertyDescriptor(e,"ref").get;if(i&&i.isReactWarning)return!1}return e.ref!==void 0}function $t(e){if(se.call(e,"key")){var i=Object.getOwnPropertyDescriptor(e,"key").get;if(i&&i.isReactWarning)return!1}return e.key!==void 0}function Ft(e,i){if(typeof e.ref=="string"&&H.current&&i&&H.current.stateNode!==i){var c=k(H.current.type);me[c]||(z('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',k(H.current.type),e.ref),me[c]=!0)}}function Bt(e,i){{var c=function(){Ue||(Ue=!0,z("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",i))};c.isReactWarning=!0,Object.defineProperty(e,"key",{get:c,configurable:!0})}}function Ut(e,i){{var c=function(){We||(We=!0,z("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",i))};c.isReactWarning=!0,Object.defineProperty(e,"ref",{get:c,configurable:!0})}}var Wt=function(e,i,c,g,w,_,v){var m={$$typeof:n,type:e,key:i,ref:c,props:v,_owner:_};return m._store={},Object.defineProperty(m._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(m,"_self",{configurable:!1,enumerable:!1,writable:!1,value:g}),Object.defineProperty(m,"_source",{configurable:!1,enumerable:!1,writable:!1,value:w}),Object.freeze&&(Object.freeze(m.props),Object.freeze(m)),m};function Vt(e,i,c,g,w){{var _,v={},m=null,O=null;c!==void 0&&(Be(c),m=""+c),$t(i)&&(Be(i.key),m=""+i.key),Mt(i)&&(O=i.ref,Ft(i,w));for(_ in i)se.call(i,_)&&!Lt.hasOwnProperty(_)&&(v[_]=i[_]);if(e&&e.defaultProps){var E=e.defaultProps;for(_ in E)v[_]===void 0&&(v[_]=E[_])}if(m||O){var A=typeof e=="function"?e.displayName||e.name||"Unknown":e;m&&Bt(v,A),O&&Ut(v,A)}return Wt(e,m,O,w,g,H.current,v)}}var ve=$.ReactCurrentOwner,Ve=$.ReactDebugCurrentFrame;function Y(e){if(e){var i=e._owner,c=oe(e.type,e._source,i?i.type:null);Ve.setExtraStackFrame(c)}else Ve.setExtraStackFrame(null)}var be;be=!1;function we(e){return typeof e=="object"&&e!==null&&e.$$typeof===n}function Ye(){{if(ve.current){var e=k(ve.current.type);if(e)return`
21
+ `+m[E].replace(" at new "," at ");return e.displayName&&I.includes("<anonymous>")&&(I=I.replace("<anonymous>",e.displayName)),typeof e=="function"&&oe.set(e,I),I}while(E>=1&&A>=0);break}}}finally{ge=!1,fe.current=y,Dt(),Error.prepareStackTrace=w}var G=e?e.displayName||e.name:"",Qe=G?ie(G):"";return typeof e=="function"&&oe.set(e,Qe),Qe}function It(e,a,c){return Le(e,!1)}function kt(e){var a=e.prototype;return!!(a&&a.isReactComponent)}function se(e,a,c){if(e==null)return"";if(typeof e=="function")return Le(e,kt(e));if(typeof e=="string")return ie(e);switch(e){case T:return ie("Suspense");case R:return ie("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case h:return It(e.render);case b:return se(e.type,a,c);case p:{var g=e,w=g._payload,y=g._init;try{return se(y(w),a,c)}catch{}}}return""}var le=Object.prototype.hasOwnProperty,Me={},$e=$.ReactDebugCurrentFrame;function ue(e){if(e){var a=e._owner,c=se(e.type,e._source,a?a.type:null);$e.setExtraStackFrame(c)}else $e.setExtraStackFrame(null)}function qt(e,a,c,g,w){{var y=Function.call.bind(le);for(var v in e)if(y(e,v)){var m=void 0;try{if(typeof e[v]!="function"){var O=Error((g||"React class")+": "+c+" type `"+v+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[v]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw O.name="Invariant Violation",O}m=e[v](a,v,g,c,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(E){m=E}m&&!(m instanceof Error)&&(ue(w),z("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",g||"React class",c,v,typeof m),ue(null)),m instanceof Error&&!(m.message in Me)&&(Me[m.message]=!0,ue(w),z("Failed %s type: %s",c,m.message),ue(null))}}}var Nt=Array.isArray;function he(e){return Nt(e)}function Lt(e){{var a=typeof Symbol=="function"&&Symbol.toStringTag,c=a&&e[Symbol.toStringTag]||e.constructor.name||"Object";return c}}function Mt(e){try{return Fe(e),!1}catch{return!0}}function Fe(e){return""+e}function Be(e){if(Mt(e))return z("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Lt(e)),Fe(e)}var H=$.ReactCurrentOwner,$t={key:!0,ref:!0,__self:!0,__source:!0},Ue,We,me;me={};function Ft(e){if(le.call(e,"ref")){var a=Object.getOwnPropertyDescriptor(e,"ref").get;if(a&&a.isReactWarning)return!1}return e.ref!==void 0}function Bt(e){if(le.call(e,"key")){var a=Object.getOwnPropertyDescriptor(e,"key").get;if(a&&a.isReactWarning)return!1}return e.key!==void 0}function Ut(e,a){if(typeof e.ref=="string"&&H.current&&a&&H.current.stateNode!==a){var c=k(H.current.type);me[c]||(z('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',k(H.current.type),e.ref),me[c]=!0)}}function Wt(e,a){{var c=function(){Ue||(Ue=!0,z("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",a))};c.isReactWarning=!0,Object.defineProperty(e,"key",{get:c,configurable:!0})}}function Vt(e,a){{var c=function(){We||(We=!0,z("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",a))};c.isReactWarning=!0,Object.defineProperty(e,"ref",{get:c,configurable:!0})}}var Yt=function(e,a,c,g,w,y,v){var m={$$typeof:n,type:e,key:a,ref:c,props:v,_owner:y};return m._store={},Object.defineProperty(m._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(m,"_self",{configurable:!1,enumerable:!1,writable:!1,value:g}),Object.defineProperty(m,"_source",{configurable:!1,enumerable:!1,writable:!1,value:w}),Object.freeze&&(Object.freeze(m.props),Object.freeze(m)),m};function Gt(e,a,c,g,w){{var y,v={},m=null,O=null;c!==void 0&&(Be(c),m=""+c),Bt(a)&&(Be(a.key),m=""+a.key),Ft(a)&&(O=a.ref,Ut(a,w));for(y in a)le.call(a,y)&&!$t.hasOwnProperty(y)&&(v[y]=a[y]);if(e&&e.defaultProps){var E=e.defaultProps;for(y in E)v[y]===void 0&&(v[y]=E[y])}if(m||O){var A=typeof e=="function"?e.displayName||e.name||"Unknown":e;m&&Wt(v,A),O&&Vt(v,A)}return Yt(e,m,O,w,g,H.current,v)}}var ve=$.ReactCurrentOwner,Ve=$.ReactDebugCurrentFrame;function Y(e){if(e){var a=e._owner,c=se(e.type,e._source,a?a.type:null);Ve.setExtraStackFrame(c)}else Ve.setExtraStackFrame(null)}var be;be=!1;function we(e){return typeof e=="object"&&e!==null&&e.$$typeof===n}function Ye(){{if(ve.current){var e=k(ve.current.type);if(e)return`
22
22
 
23
- Check the render method of \``+e+"`."}return""}}function Yt(e){{if(e!==void 0){var i=e.fileName.replace(/^.*[\\\/]/,""),c=e.lineNumber;return`
23
+ Check the render method of \``+e+"`."}return""}}function Kt(e){{if(e!==void 0){var a=e.fileName.replace(/^.*[\\\/]/,""),c=e.lineNumber;return`
24
24
 
25
- Check your code at `+i+":"+c+"."}return""}}var Ge={};function Gt(e){{var i=Ye();if(!i){var c=typeof e=="string"?e:e.displayName||e.name;c&&(i=`
25
+ Check your code at `+a+":"+c+"."}return""}}var Ge={};function Jt(e){{var a=Ye();if(!a){var c=typeof e=="string"?e:e.displayName||e.name;c&&(a=`
26
26
 
27
- Check the top-level render call using <`+c+">.")}return i}}function Ke(e,i){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var c=Gt(i);if(Ge[c])return;Ge[c]=!0;var g="";e&&e._owner&&e._owner!==ve.current&&(g=" It was passed a child from "+k(e._owner.type)+"."),Y(e),z('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',c,g),Y(null)}}function Je(e,i){{if(typeof e!="object")return;if(he(e))for(var c=0;c<e.length;c++){var g=e[c];we(g)&&Ke(g,i)}else if(we(e))e._store&&(e._store.validated=!0);else if(e){var w=de(e);if(typeof w=="function"&&w!==e.entries)for(var _=w.call(e),v;!(v=_.next()).done;)we(v.value)&&Ke(v.value,i)}}}function Kt(e){{var i=e.type;if(i==null||typeof i=="string")return;var c;if(typeof i=="function")c=i.propTypes;else if(typeof i=="object"&&(i.$$typeof===h||i.$$typeof===b))c=i.propTypes;else return;if(c){var g=k(i);It(c,e.props,"prop",g,e)}else if(i.PropTypes!==void 0&&!be){be=!0;var w=k(i);z("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",w||"Unknown")}typeof i.getDefaultProps=="function"&&!i.getDefaultProps.isReactClassApproved&&z("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Jt(e){{for(var i=Object.keys(e.props),c=0;c<i.length;c++){var g=i[c];if(g!=="children"&&g!=="key"){Y(e),z("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",g),Y(null);break}}e.ref!==null&&(Y(e),z("Invalid attribute `ref` supplied to `React.Fragment`."),Y(null))}}function Xe(e,i,c,g,w,_){{var v=Et(e);if(!v){var m="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(m+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var O=Yt(w);O?m+=O:m+=Ye();var E;e===null?E="null":he(e)?E="array":e!==void 0&&e.$$typeof===n?(E="<"+(k(e.type)||"Unknown")+" />",m=" Did you accidentally export a JSX literal instead of a component?"):E=typeof e,z("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",E,m)}var A=Vt(e,i,c,w,_);if(A==null)return A;if(v){var I=i.children;if(I!==void 0)if(g)if(he(I)){for(var G=0;G<I.length;G++)Je(I[G],e);Object.freeze&&Object.freeze(I)}else z("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Je(I,e)}return e===l?Jt(A):Kt(A),A}}function Xt(e,i,c){return Xe(e,i,c,!0)}function Qt(e,i,c){return Xe(e,i,c,!1)}var Zt=Qt,Ht=Xt;Q.Fragment=l,Q.jsx=Zt,Q.jsxs=Ht}()),Q}(function(r){process.env.NODE_ENV==="production"?r.exports=it():r.exports=at()})(re);const N=re.exports.Fragment,t=re.exports.jsx,y=re.exports.jsxs;function ot({postSubmit:r,styles:n=te}){const{control:s,handleSubmit:l}=S.useForm({defaultValues:{type:"postgresql",key:"",config:{host:"",port:5432,username:"",password:"",database:""}}}),u=async({type:a,key:d,config:f})=>{if(C.showNotification({id:"for-creating",title:"Pending",message:"Adding data source...",loading:!0}),!await D.datasource.create(a,d,f)){C.updateNotification({id:"for-creating",title:"Failed",message:"Test connection failed with given info",color:"red"});return}C.updateNotification({id:"for-creating",title:"Successful",message:"Data source is added",color:"green"}),r()};return t(o.Box,{mx:"auto",children:y("form",{onSubmit:l(u),children:[t(S.Controller,{name:"type",control:s,render:({field:a})=>t(o.SegmentedControl,{fullWidth:!0,mb:n.spacing,size:n.size,data:[{label:"PostgreSQL",value:"postgresql"},{label:"MySQL",value:"mysql"},{label:"HTTP",value:"http",disabled:!0}],...a})}),t(S.Controller,{name:"key",control:s,render:({field:a})=>t(o.TextInput,{mb:n.spacing,size:n.size,required:!0,label:"Name",placeholder:"A unique name",...a})}),t(o.Divider,{label:"Connection Info",labelPosition:"center"}),y(o.Group,{grow:!0,children:[t(S.Controller,{name:"config.host",control:s,render:({field:a})=>t(o.TextInput,{mb:n.spacing,size:n.size,required:!0,label:"Host",sx:{flexGrow:1},...a})}),t(S.Controller,{name:"config.port",control:s,render:({field:a})=>t(o.NumberInput,{mb:n.spacing,size:n.size,required:!0,label:"Port",hideControls:!0,sx:{width:"8em"},...a})})]}),t(S.Controller,{name:"config.username",control:s,render:({field:a})=>t(o.TextInput,{mb:n.spacing,size:n.size,required:!0,label:"Username",...a})}),t(S.Controller,{name:"config.password",control:s,render:({field:a})=>t(o.PasswordInput,{mb:n.spacing,size:n.size,required:!0,label:"Password",...a})}),t(S.Controller,{name:"config.database",control:s,render:({field:a})=>t(o.TextInput,{mb:n.spacing,size:n.size,required:!0,label:"Database",...a})}),t(o.Group,{position:"right",mt:n.spacing,children:t(o.Button,{type:"submit",size:n.button.size,children:"Save"})})]})})}function Se({onSuccess:r,styles:n=te}){const[s,l]=V.default.useState(!1),u=()=>l(!0),a=()=>l(!1),d=()=>{r(),a()};return y(N,{children:[t(o.Modal,{overflow:"inside",opened:s,onClose:()=>l(!1),title:"Add a data source",trapFocus:!0,onDragStart:f=>{f.stopPropagation()},children:t(ot,{postSubmit:d,styles:n})}),t(o.Button,{size:n.button.size,onClick:u,leftIcon:t(F.PlaylistAdd,{size:20}),children:"Add a Data Source"})]})}function st(r,n){if(r==null)return{};var s={},l=Object.keys(r),u,a;for(a=0;a<l.length;a++)u=l[a],!(n.indexOf(u)>=0)&&(s[u]=r[u]);return s}function lt(r,n){if(r==null)return{};var s=st(r,n),l,u;if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(r);for(u=0;u<a.length;u++)l=a[u],!(n.indexOf(l)>=0)&&(!Object.prototype.propertyIsEnumerable.call(r,l)||(s[l]=r[l]))}return s}var ut=["size","color","stroke"];function ct(r){var n=r.size,s=n===void 0?24:n,l=r.color,u=l===void 0?"currentColor":l,a=r.stroke,d=a===void 0?2:a,f=lt(r,ut);return y("svg",{xmlns:"http://www.w3.org/2000/svg",className:"icon icon-tabler icon-tabler-lock",width:s,height:s,viewBox:"0 0 24 24",strokeWidth:d,stroke:u,fill:"none",strokeLinecap:"round",strokeLinejoin:"round",...f,children:[t("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),t("rect",{x:5,y:11,width:14,height:10,rx:2}),t("circle",{cx:12,cy:16,r:1}),t("path",{d:"M8 11v-4a4 4 0 0 1 8 0v4"})]})}function Pe({id:r,name:n,isProtected:s,onSuccess:l,styles:u=te}){const a=J.useModals(),d=async()=>{!r||(C.showNotification({id:"for-deleting",title:"Pending",message:"Deleting data source...",loading:!0}),await D.datasource.delete(r),C.updateNotification({id:"for-deleting",title:"Successful",message:`Data source [${n}] is deleted`,color:"green"}),l())},f=()=>a.openConfirmModal({title:"Delete this data source?",children:t(o.Text,{size:u.size,children:"This action won't affect your database."}),labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:d}),h=o.useMantineTheme();return s?t(o.Tooltip,{withArrow:!0,events:{hover:!0,touch:!1,focus:!1},label:"This is a preset datasource, it can not be deleted",children:t("span",{children:t(ct,{size:16,color:h.colors.gray[7]})})}):t(o.Button,{size:u.button.size,color:"red",onClick:f,leftIcon:t(F.Trash,{size:20}),children:"Delete"})}function dt({styles:r=te,config:n}){ee(n);const{data:s=[],loading:l,refresh:u}=W.useRequest(async()=>{const{data:a}=await D.datasource.list();return a},{refreshDeps:[]});return y(N,{children:[t(o.Group,{pt:r.spacing,position:"right",children:t(Se,{onSuccess:u})}),y(o.Box,{mt:r.spacing,sx:{position:"relative"},children:[t(o.LoadingOverlay,{visible:l}),y(o.Table,{horizontalSpacing:r.spacing,verticalSpacing:r.spacing,fontSize:r.size,highlightOnHover:!0,children:[t("thead",{children:y("tr",{children:[t("th",{children:"Type"}),t("th",{children:"Name"}),t("th",{children:"Action"})]})}),t("tbody",{children:s.map(({id:a,key:d,type:f,is_preset:h})=>y("tr",{children:[t("td",{width:200,children:f}),t("td",{children:d}),t("td",{width:200,children:t(o.Group,{position:"left",children:t(Pe,{isProtected:h,id:a,name:d,onSuccess:u})})})]},d))})]})]})]})}const ft=K.forwardRef(({label:r,value:n,description:s,...l},u)=>y(o.Stack,{spacing:2,ref:u,...l,children:[t(o.Text,{size:"sm",children:r}),t(o.Text,{size:"xs",color:"dimmed",className:"role-description",children:s})]})),ce=K.forwardRef(({styles:r,value:n,onChange:s},l)=>{const{data:u=[],loading:a}=W.useRequest(async()=>(await D.role.list()).map(f=>({label:f.name,value:f.id,description:f.description,disabled:f.id===50})),{refreshDeps:[]});return t(o.Select,{ref:l,mb:r.spacing,size:r.size,required:!0,label:"Role",itemComponent:ft,data:u,disabled:a,styles:()=>({item:{"&[data-selected]":{"&, &:hover":{".role-description":{color:"rgba(255,255,255,.8)"}}}}}),value:n,onChange:s})}),L={size:"sm",spacing:"md",button:{size:"xs"}};function pt({postSubmit:r,styles:n=L,initialRoleID:s}){const{control:l,handleSubmit:u}=S.useForm({defaultValues:{name:"",email:"",role_id:s,password:""}}),a=async({name:d,email:f,password:h,role_id:T})=>{try{C.showNotification({id:"for-creating",title:"Pending",message:"Adding account...",loading:!0}),await D.account.create(d,f,h,T),C.updateNotification({id:"for-creating",title:"Successful",message:"Account is added",color:"green"}),r()}catch(P){C.updateNotification({id:"for-creating",title:"Failed",message:P.message,color:"red"})}};return t(o.Box,{mx:"auto",children:y("form",{onSubmit:u(a),children:[t(S.Controller,{name:"name",control:l,render:({field:d})=>t(o.TextInput,{mb:n.spacing,size:n.size,required:!0,label:"Username",...d})}),t(S.Controller,{name:"email",control:l,render:({field:d})=>t(o.TextInput,{mb:n.spacing,size:n.size,required:!0,label:"Email",...d})}),t(S.Controller,{name:"password",control:l,render:({field:d})=>t(o.PasswordInput,{mb:n.spacing,size:n.size,required:!0,label:"Password",description:"Password must be at least 8 characters long",...d})}),t(S.Controller,{name:"role_id",control:l,render:({field:d})=>t(ce,{styles:n,...d})}),t(o.Group,{position:"right",mt:n.spacing,children:t(o.Button,{type:"submit",size:n.button.size,children:"Save"})})]})})}function Re({onSuccess:r,styles:n=L,initialRoleID:s}){const[l,u]=V.default.useState(!1),a=()=>u(!0),d=()=>u(!1),f=()=>{r(),d()};return y(N,{children:[t(o.Modal,{overflow:"inside",opened:l,onClose:()=>u(!1),title:"Add an Account",trapFocus:!0,onDragStart:h=>{h.stopPropagation()},children:t(pt,{postSubmit:f,styles:n,initialRoleID:s})}),t(o.Button,{size:n.button.size,onClick:a,leftIcon:t(F.PlaylistAdd,{size:20}),children:"Add an Account"})]})}function Ce({id:r,name:n,onSuccess:s,styles:l=L}){const u=J.useModals(),a=async()=>{if(!!r){C.showNotification({id:"for-deleting",title:"Pending",message:"Deleting account...",loading:!0});try{await D.account.delete(r),C.updateNotification({id:"for-deleting",title:"Successful",message:`Account [${n}] is deleted`,color:"green"}),s()}catch(f){C.updateNotification({id:"for-deleting",title:"Failed",message:f.message,color:"red"})}}},d=()=>u.openConfirmModal({title:"Delete this account?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:a});return t(o.Button,{size:l.button.size,color:"red",onClick:d,leftIcon:t(F.Trash,{size:20}),children:"Delete"})}function gt({id:r,name:n,email:s,role_id:l,postSubmit:u,styles:a=L}){const{control:d,handleSubmit:f,watch:h}=S.useForm({defaultValues:{name:n,email:s,role_id:l,reset_password:!1,new_password:""}}),T=async({name:p,email:j,role_id:M,reset_password:B,new_password:de})=>{try{C.showNotification({id:"for-updating",title:"Pending",message:"Updating account...",loading:!0}),await D.account.edit({id:r,name:p,email:j,role_id:M,reset_password:B,new_password:de}),C.updateNotification({id:"for-updating",title:"Successful",message:"Account is updated",color:"green"}),u()}catch($){C.updateNotification({id:"for-updating",title:"Failed",message:$.message,color:"red"})}},[P,b]=h(["reset_password","new_password"]);return t(o.Box,{mx:"auto",children:y("form",{onSubmit:f(T),children:[t(S.Controller,{name:"name",control:d,render:({field:p})=>t(o.TextInput,{mb:a.spacing,size:a.size,required:!0,label:"Username",...p})}),t(S.Controller,{name:"email",control:d,render:({field:p})=>t(o.TextInput,{mb:a.spacing,size:a.size,required:!0,label:"Email",...p})}),t(S.Controller,{name:"role_id",control:d,render:({field:p})=>t(ce,{styles:a,...p})}),t(o.Divider,{my:20,variant:"dashed",label:"",labelPosition:"center"}),t(S.Controller,{name:"reset_password",control:d,render:({field:p})=>t(o.Switch,{mb:a.spacing,size:a.size,label:"Reset password",checked:p.value,onChange:j=>p.onChange(j.currentTarget.checked),styles:{label:{verticalAlign:"middle"}}})}),P&&t(S.Controller,{name:"new_password",control:d,render:({field:p})=>t(o.PasswordInput,{autoComplete:"off",mb:a.spacing,size:a.size,required:!0,description:"Password must be at least 8 characters long",label:"New Password",...p})}),t(o.Group,{position:"right",mt:a.spacing,children:t(o.Button,{type:"submit",size:a.button.size,children:"Submit"})})]})})}function ht({account:r,onSuccess:n,styles:s=L}){const[l,u]=V.default.useState(!1),a=()=>u(!0),d=()=>u(!1),f=()=>{n(),d()};return y(N,{children:[t(o.Modal,{overflow:"inside",opened:l,onClose:()=>u(!1),title:`Editing ${r.name}`,trapFocus:!0,onDragStart:h=>{h.stopPropagation()},children:t(gt,{...r,postSubmit:f,styles:s})}),t(o.Button,{size:s.button.size,onClick:a,leftIcon:t(F.Edit,{size:20}),children:"Edit"})]})}function mt({styles:r=L,config:n}){var T,P;ee(n);const{data:s=[],loading:l,refresh:u}=W.useRequest(async()=>{const{data:b}=await D.account.list();return b},{refreshDeps:[]}),{data:a=[],loading:d}=W.useRequest(async()=>(await D.role.list()).map(p=>({label:p.name,value:p.id,description:p.description,disabled:p.id===50})),{refreshDeps:[]}),f=K.useMemo(()=>a.reduce((b,p)=>(b.set(p.value,p.label),b),new Map),[a]),h=b=>{var p;return(p=f.get(b))!=null?p:b};return y(N,{children:[t(o.Group,{pt:r.spacing,position:"right",children:t(Re,{onSuccess:u,initialRoleID:(P=(T=a==null?void 0:a[0])==null?void 0:T.value)!=null?P:0})}),y(o.Box,{mt:r.spacing,sx:{position:"relative"},children:[t(o.LoadingOverlay,{visible:l||d}),y(o.Table,{horizontalSpacing:r.spacing,verticalSpacing:r.spacing,fontSize:r.size,highlightOnHover:!0,children:[t("thead",{children:y("tr",{children:[t("th",{children:"Username"}),t("th",{children:"Email"}),t("th",{children:"Role"}),t("th",{children:"Action"})]})}),t("tbody",{children:s.map(b=>{const{id:p,name:j,email:M,role_id:B}=b;return y("tr",{children:[t("td",{width:200,children:j}),t("td",{width:200,children:M}),t("td",{width:200,children:h(B)}),t("td",{width:200,children:y(o.Group,{position:"left",children:[t(ht,{account:b,onSuccess:u}),t(Ce,{id:p,name:j,onSuccess:u})]})})]},p)})})]})]})]})}function vt({postSubmit:r,styles:n=L}){const{control:s,handleSubmit:l}=S.useForm({defaultValues:{name:"",password:""}}),u=async({name:a,password:d})=>{try{C.showNotification({id:"for-login",title:"Pending",message:"Loggin in...",loading:!0});const f=await D.account.login(a,d);window.localStorage.setItem("token",f.token),C.updateNotification({id:"for-login",title:"Successful",message:"Logged in",color:"green"}),r(f)}catch(f){C.updateNotification({id:"for-login",title:"Login Failed",message:f.message,color:"red"})}};return t(o.Box,{mx:"auto",children:y("form",{onSubmit:l(u),children:[t(S.Controller,{name:"name",control:s,render:({field:a})=>t(o.TextInput,{mb:n.spacing,size:n.size,required:!0,label:"Username",...a})}),t(S.Controller,{name:"password",control:s,render:({field:a})=>t(o.PasswordInput,{mb:n.spacing,size:n.size,required:!0,label:"Password",...a})}),t(o.Group,{position:"right",mt:n.spacing,children:t(o.Button,{type:"submit",size:n.button.size,children:"Submit"})})]})})}function bt({styles:r=L,config:n,onSuccess:s}){return ee(n),t(N,{children:t(o.Box,{mt:r.spacing,sx:{position:"relative"},children:t(vt,{styles:r,postSubmit:s})})})}const ne={size:"sm",spacing:"md",button:{size:"xs"}};function wt({postSubmit:r,styles:n=ne,initialRoleID:s}){const{control:l,handleSubmit:u}=S.useForm({defaultValues:{name:"",role_id:s}}),a=async({name:d,role_id:f})=>{try{C.showNotification({id:"for-creating",title:"Pending",message:"Adding API Key...",loading:!0});const{app_id:h,app_secret:T}=await D.api_key.create(d,f);C.updateNotification({id:"for-creating",title:"Successful",message:"API Key is added",color:"green"}),r(h,T)}catch(h){C.updateNotification({id:"for-creating",title:"Failed",message:h.message,color:"red"})}};return t(o.Box,{mx:"auto",children:y("form",{onSubmit:u(a),children:[t(S.Controller,{name:"name",control:l,render:({field:d})=>t(o.TextInput,{mb:n.spacing,size:n.size,required:!0,label:"Name",...d})}),t(S.Controller,{name:"role_id",control:l,render:({field:d})=>t(ce,{styles:n,...d})}),t(o.Group,{position:"right",mt:n.spacing,children:t(o.Button,{type:"submit",size:n.button.size,children:"Save"})})]})})}function Te({onSuccess:r,styles:n=ne,initialRoleID:s}){const l=J.useModals(),[u,a]=V.default.useState(!1),d=()=>a(!0),f=()=>a(!1),h=(T,P)=>{f(),l.openModal({title:"API Key is generated",children:y(o.Stack,{children:[t(o.Text,{color:"dimmed",children:"Make sure you save it - you won't be able to access it again."}),t(o.TextInput,{defaultValue:T,disabled:!0,label:"APP ID",styles:{input:{cursor:"text !important"}}}),t(o.TextInput,{defaultValue:P,disabled:!0,label:"APP Secret",styles:{input:{cursor:"text !important"}}}),t(o.Button,{size:"sm",onClick:()=>{J.closeAllModals()},children:"I've saved this API Key"})]}),onClose:()=>{r()}})};return y(N,{children:[t(o.Modal,{overflow:"inside",opened:u,onClose:()=>a(!1),title:"Add an API Key",trapFocus:!0,onDragStart:T=>{T.stopPropagation()},children:t(wt,{postSubmit:h,styles:n,initialRoleID:s})}),t(o.Button,{size:n.button.size,onClick:d,leftIcon:t(F.PlaylistAdd,{size:20}),children:"Add an API Key"})]})}function Ee({id:r,name:n,onSuccess:s,styles:l=ne}){const u=J.useModals(),a=async()=>{if(!!r){C.showNotification({id:"for-deleting",title:"Pending",message:"Deleting API Key...",loading:!0});try{await D.api_key.delete(r),C.updateNotification({id:"for-deleting",title:"Successful",message:`API Key [${n}] is deleted`,color:"green"}),s()}catch(f){C.updateNotification({id:"for-deleting",title:"Failed",message:f.message,color:"red"})}}},d=()=>u.openConfirmModal({title:"Delete this api-key?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:a});return t(o.Button,{size:l.button.size,color:"red",onClick:d,leftIcon:t(F.Trash,{size:20}),children:"Delete"})}function yt({styles:r=ne,config:n}){var T,P;ee(n);const{data:s=[],loading:l,refresh:u}=W.useRequest(async()=>{const{data:b}=await D.api_key.list();return b},{refreshDeps:[]}),{data:a=[],loading:d}=W.useRequest(async()=>(await D.role.list()).map(p=>({label:p.name,value:p.id,description:p.description,disabled:p.id===50})),{refreshDeps:[]}),f=K.useMemo(()=>a.reduce((b,p)=>(b.set(p.value,p.label),b),new Map),[a]),h=b=>{var p;return(p=f.get(b))!=null?p:b};return y(N,{children:[t(o.Group,{pt:r.spacing,position:"right",children:t(Te,{onSuccess:u,initialRoleID:(P=(T=a==null?void 0:a[0])==null?void 0:T.value)!=null?P:0})}),y(o.Box,{mt:r.spacing,sx:{position:"relative"},children:[t(o.LoadingOverlay,{visible:l||d}),y(o.Table,{horizontalSpacing:r.spacing,verticalSpacing:r.spacing,fontSize:r.size,highlightOnHover:!0,children:[t("thead",{children:y("tr",{children:[t("th",{children:"Name"}),t("th",{children:"APP ID"}),t("th",{children:"Role"}),t("th",{children:"Action"})]})}),t("tbody",{children:s.map(b=>{const{id:p,name:j,app_id:M,role_id:B}=b;return y("tr",{children:[t("td",{width:200,children:j}),t("td",{width:200,children:M}),t("td",{width:200,children:h(B)}),t("td",{width:200,children:t(o.Group,{position:"left",children:t(Ee,{id:p,name:j,onSuccess:u})})})]},p)})})]})]})]})}R.APIKeyList=yt,R.AccountList=mt,R.AddAPIKey=Te,R.AddAccount=Re,R.AddDataSource=Se,R.DataSourceList=dt,R.DeleteAPIKey=Ee,R.DeleteAccount=Ce,R.DeleteDataSource=Pe,R.Login=bt,Object.defineProperties(R,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
27
+ Check the top-level render call using <`+c+">.")}return a}}function Ke(e,a){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var c=Jt(a);if(Ge[c])return;Ge[c]=!0;var g="";e&&e._owner&&e._owner!==ve.current&&(g=" It was passed a child from "+k(e._owner.type)+"."),Y(e),z('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',c,g),Y(null)}}function Je(e,a){{if(typeof e!="object")return;if(he(e))for(var c=0;c<e.length;c++){var g=e[c];we(g)&&Ke(g,a)}else if(we(e))e._store&&(e._store.validated=!0);else if(e){var w=de(e);if(typeof w=="function"&&w!==e.entries)for(var y=w.call(e),v;!(v=y.next()).done;)we(v.value)&&Ke(v.value,a)}}}function Xt(e){{var a=e.type;if(a==null||typeof a=="string")return;var c;if(typeof a=="function")c=a.propTypes;else if(typeof a=="object"&&(a.$$typeof===h||a.$$typeof===b))c=a.propTypes;else return;if(c){var g=k(a);qt(c,e.props,"prop",g,e)}else if(a.PropTypes!==void 0&&!be){be=!0;var w=k(a);z("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",w||"Unknown")}typeof a.getDefaultProps=="function"&&!a.getDefaultProps.isReactClassApproved&&z("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Qt(e){{for(var a=Object.keys(e.props),c=0;c<a.length;c++){var g=a[c];if(g!=="children"&&g!=="key"){Y(e),z("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",g),Y(null);break}}e.ref!==null&&(Y(e),z("Invalid attribute `ref` supplied to `React.Fragment`."),Y(null))}}function Xe(e,a,c,g,w,y){{var v=xt(e);if(!v){var m="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(m+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var O=Kt(w);O?m+=O:m+=Ye();var E;e===null?E="null":he(e)?E="array":e!==void 0&&e.$$typeof===n?(E="<"+(k(e.type)||"Unknown")+" />",m=" Did you accidentally export a JSX literal instead of a component?"):E=typeof e,z("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",E,m)}var A=Gt(e,a,c,w,y);if(A==null)return A;if(v){var I=a.children;if(I!==void 0)if(g)if(he(I)){for(var G=0;G<I.length;G++)Je(I[G],e);Object.freeze&&Object.freeze(I)}else z("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Je(I,e)}return e===l?Qt(A):Xt(A),A}}function Zt(e,a,c){return Xe(e,a,c,!0)}function Ht(e,a,c){return Xe(e,a,c,!1)}var er=Ht,tr=Zt;Q.Fragment=l,Q.jsx=er,Q.jsxs=tr}()),Q}(function(r){process.env.NODE_ENV==="production"?r.exports=ot():r.exports=st()})(ne);const N=ne.exports.Fragment,t=ne.exports.jsx,_=ne.exports.jsxs;function lt({postSubmit:r,styles:n=re}){const{control:s,handleSubmit:l}=P.useForm({defaultValues:{type:"postgresql",key:"",config:{host:"",port:5432,username:"",password:"",database:""}}}),u=async({type:i,key:d,config:f})=>{C.showNotification({id:"for-creating",title:"Pending",message:"Adding data source...",loading:!0});try{await D.datasource.create(i,d,f),C.updateNotification({id:"for-creating",title:"Successful",message:"Data source is added",color:"green"}),r()}catch(h){C.updateNotification({id:"for-creating",title:"Failed",message:h.message,color:"red"})}};return t(o.Box,{mx:"auto",children:_("form",{onSubmit:l(u),children:[t(P.Controller,{name:"type",control:s,render:({field:i})=>t(o.SegmentedControl,{fullWidth:!0,mb:n.spacing,size:n.size,data:[{label:"PostgreSQL",value:"postgresql"},{label:"MySQL",value:"mysql"},{label:"HTTP",value:"http",disabled:!0}],...i})}),t(P.Controller,{name:"key",control:s,render:({field:i})=>t(o.TextInput,{mb:n.spacing,size:n.size,required:!0,label:"Name",placeholder:"A unique name",...i})}),t(o.Divider,{label:"Connection Info",labelPosition:"center"}),_(o.Group,{grow:!0,children:[t(P.Controller,{name:"config.host",control:s,render:({field:i})=>t(o.TextInput,{mb:n.spacing,size:n.size,required:!0,label:"Host",sx:{flexGrow:1},...i})}),t(P.Controller,{name:"config.port",control:s,render:({field:i})=>t(o.NumberInput,{mb:n.spacing,size:n.size,required:!0,label:"Port",hideControls:!0,sx:{width:"8em"},...i})})]}),t(P.Controller,{name:"config.username",control:s,render:({field:i})=>t(o.TextInput,{mb:n.spacing,size:n.size,required:!0,label:"Username",...i})}),t(P.Controller,{name:"config.password",control:s,render:({field:i})=>t(o.PasswordInput,{mb:n.spacing,size:n.size,required:!0,label:"Password",...i})}),t(P.Controller,{name:"config.database",control:s,render:({field:i})=>t(o.TextInput,{mb:n.spacing,size:n.size,required:!0,label:"Database",...i})}),t(o.Group,{position:"right",mt:n.spacing,children:t(o.Button,{type:"submit",size:n.button.size,children:"Save"})})]})})}function Se({onSuccess:r,styles:n=re}){const[s,l]=V.default.useState(!1),u=()=>l(!0),i=()=>l(!1),d=()=>{r(),i()};return _(N,{children:[t(o.Modal,{overflow:"inside",opened:s,onClose:()=>l(!1),title:"Add a data source",trapFocus:!0,onDragStart:f=>{f.stopPropagation()},children:t(lt,{postSubmit:d,styles:n})}),t(o.Button,{size:n.button.size,onClick:u,leftIcon:t(F.PlaylistAdd,{size:20}),children:"Add a Data Source"})]})}function ut(r,n){if(r==null)return{};var s={},l=Object.keys(r),u,i;for(i=0;i<l.length;i++)u=l[i],!(n.indexOf(u)>=0)&&(s[u]=r[u]);return s}function ct(r,n){if(r==null)return{};var s=ut(r,n),l,u;if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(r);for(u=0;u<i.length;u++)l=i[u],!(n.indexOf(l)>=0)&&(!Object.prototype.propertyIsEnumerable.call(r,l)||(s[l]=r[l]))}return s}var dt=["size","color","stroke"];function ft(r){var n=r.size,s=n===void 0?24:n,l=r.color,u=l===void 0?"currentColor":l,i=r.stroke,d=i===void 0?2:i,f=ct(r,dt);return _("svg",{xmlns:"http://www.w3.org/2000/svg",className:"icon icon-tabler icon-tabler-lock",width:s,height:s,viewBox:"0 0 24 24",strokeWidth:d,stroke:u,fill:"none",strokeLinecap:"round",strokeLinejoin:"round",...f,children:[t("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),t("rect",{x:5,y:11,width:14,height:10,rx:2}),t("circle",{cx:12,cy:16,r:1}),t("path",{d:"M8 11v-4a4 4 0 0 1 8 0v4"})]})}function Pe({id:r,name:n,isProtected:s,onSuccess:l,styles:u=re}){const i=J.useModals(),d=async()=>{!r||(C.showNotification({id:"for-deleting",title:"Pending",message:"Deleting data source...",loading:!0}),await D.datasource.delete(r),C.updateNotification({id:"for-deleting",title:"Successful",message:`Data source [${n}] is deleted`,color:"green"}),l())},f=()=>i.openConfirmModal({title:"Delete this data source?",children:t(o.Text,{size:u.size,children:"This action won't affect your database."}),labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:d}),h=o.useMantineTheme();return s?t(o.Tooltip,{withArrow:!0,events:{hover:!0,touch:!1,focus:!1},label:"This is a preset datasource, it can not be deleted",children:t("span",{children:t(ft,{size:16,color:h.colors.gray[7]})})}):t(o.Button,{size:u.button.size,color:"red",onClick:f,leftIcon:t(F.Trash,{size:20}),children:"Delete"})}function pt({styles:r=re,config:n}){te(n);const{data:s=[],loading:l,refresh:u}=W.useRequest(async()=>{const{data:i}=await D.datasource.list();return i},{refreshDeps:[]});return _(N,{children:[t(o.Group,{pt:r.spacing,position:"right",children:t(Se,{onSuccess:u})}),_(o.Box,{mt:r.spacing,sx:{position:"relative"},children:[t(o.LoadingOverlay,{visible:l}),_(o.Table,{horizontalSpacing:r.spacing,verticalSpacing:r.spacing,fontSize:r.size,highlightOnHover:!0,children:[t("thead",{children:_("tr",{children:[t("th",{children:"Type"}),t("th",{children:"Name"}),t("th",{children:"Action"})]})}),t("tbody",{children:s.map(({id:i,key:d,type:f,is_preset:h})=>_("tr",{children:[t("td",{width:200,children:f}),t("td",{children:d}),t("td",{width:200,children:t(o.Group,{position:"left",children:t(Pe,{isProtected:h,id:i,name:d,onSuccess:u})})})]},d))})]})]})]})}const gt=K.forwardRef(({label:r,value:n,description:s,...l},u)=>_(o.Stack,{spacing:2,ref:u,...l,children:[t(o.Text,{size:"sm",children:r}),t(o.Text,{size:"xs",color:"dimmed",className:"role-description",children:s})]})),ce=K.forwardRef(({styles:r,value:n,onChange:s},l)=>{const{data:u=[],loading:i}=W.useRequest(async()=>(await D.role.list()).map(f=>({label:f.name,value:f.id,description:f.description,disabled:f.id===50})),{refreshDeps:[]});return t(o.Select,{ref:l,mb:r.spacing,size:r.size,required:!0,label:"Role",itemComponent:gt,data:u,disabled:i,styles:()=>({item:{"&[data-selected]":{"&, &:hover":{".role-description":{color:"rgba(255,255,255,.8)"}}}}}),value:n,onChange:s})}),L={size:"sm",spacing:"md",button:{size:"xs"}};function ht({postSubmit:r,styles:n=L,initialRoleID:s}){const{control:l,handleSubmit:u}=P.useForm({defaultValues:{name:"",email:"",role_id:s,password:""}}),i=async({name:d,email:f,password:h,role_id:T})=>{try{C.showNotification({id:"for-creating",title:"Pending",message:"Adding account...",loading:!0}),await D.account.create(d,f,h,T),C.updateNotification({id:"for-creating",title:"Successful",message:"Account is added",color:"green"}),r()}catch(R){C.updateNotification({id:"for-creating",title:"Failed",message:R.message,color:"red"})}};return t(o.Box,{mx:"auto",children:_("form",{onSubmit:u(i),children:[t(P.Controller,{name:"name",control:l,render:({field:d})=>t(o.TextInput,{mb:n.spacing,size:n.size,required:!0,label:"Username",...d})}),t(P.Controller,{name:"email",control:l,render:({field:d})=>t(o.TextInput,{mb:n.spacing,size:n.size,required:!0,label:"Email",...d})}),t(P.Controller,{name:"password",control:l,render:({field:d})=>t(o.PasswordInput,{mb:n.spacing,size:n.size,required:!0,label:"Password",description:"Password must be at least 8 characters long",...d})}),t(P.Controller,{name:"role_id",control:l,render:({field:d})=>t(ce,{styles:n,...d})}),t(o.Group,{position:"right",mt:n.spacing,children:t(o.Button,{type:"submit",size:n.button.size,children:"Save"})})]})})}function Re({onSuccess:r,styles:n=L,initialRoleID:s}){const[l,u]=V.default.useState(!1),i=()=>u(!0),d=()=>u(!1),f=()=>{r(),d()};return _(N,{children:[t(o.Modal,{overflow:"inside",opened:l,onClose:()=>u(!1),title:"Add an Account",trapFocus:!0,onDragStart:h=>{h.stopPropagation()},children:t(ht,{postSubmit:f,styles:n,initialRoleID:s})}),t(o.Button,{size:n.button.size,onClick:i,leftIcon:t(F.PlaylistAdd,{size:20}),children:"Add an Account"})]})}function Ce({id:r,name:n,onSuccess:s,styles:l=L}){const u=J.useModals(),i=async()=>{if(!!r){C.showNotification({id:"for-deleting",title:"Pending",message:"Deleting account...",loading:!0});try{await D.account.delete(r),C.updateNotification({id:"for-deleting",title:"Successful",message:`Account [${n}] is deleted`,color:"green"}),s()}catch(f){C.updateNotification({id:"for-deleting",title:"Failed",message:f.message,color:"red"})}}},d=()=>u.openConfirmModal({title:"Delete this account?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:i});return t(o.Button,{size:l.button.size,color:"red",onClick:d,leftIcon:t(F.Trash,{size:20}),children:"Delete"})}function mt({id:r,name:n,email:s,role_id:l,postSubmit:u,styles:i=L}){const{control:d,handleSubmit:f,watch:h}=P.useForm({defaultValues:{name:n,email:s,role_id:l,reset_password:!1,new_password:""}}),T=async({name:p,email:j,role_id:M,reset_password:B,new_password:de})=>{try{C.showNotification({id:"for-updating",title:"Pending",message:"Updating account...",loading:!0}),await D.account.edit({id:r,name:p,email:j,role_id:M,reset_password:B,new_password:de}),C.updateNotification({id:"for-updating",title:"Successful",message:"Account is updated",color:"green"}),u()}catch($){C.updateNotification({id:"for-updating",title:"Failed",message:$.message,color:"red"})}},[R,b]=h(["reset_password","new_password"]);return t(o.Box,{mx:"auto",children:_("form",{onSubmit:f(T),children:[t(P.Controller,{name:"name",control:d,render:({field:p})=>t(o.TextInput,{mb:i.spacing,size:i.size,required:!0,label:"Username",...p})}),t(P.Controller,{name:"email",control:d,render:({field:p})=>t(o.TextInput,{mb:i.spacing,size:i.size,required:!0,label:"Email",...p})}),t(P.Controller,{name:"role_id",control:d,render:({field:p})=>t(ce,{styles:i,...p})}),t(o.Divider,{my:20,variant:"dashed",label:"",labelPosition:"center"}),t(P.Controller,{name:"reset_password",control:d,render:({field:p})=>t(o.Switch,{mb:i.spacing,size:i.size,label:"Reset password",checked:p.value,onChange:j=>p.onChange(j.currentTarget.checked),styles:{label:{verticalAlign:"middle"}}})}),R&&t(P.Controller,{name:"new_password",control:d,render:({field:p})=>t(o.PasswordInput,{autoComplete:"off",mb:i.spacing,size:i.size,required:!0,description:"Password must be at least 8 characters long",label:"New Password",...p})}),t(o.Group,{position:"right",mt:i.spacing,children:t(o.Button,{type:"submit",size:i.button.size,children:"Submit"})})]})})}function vt({account:r,onSuccess:n,styles:s=L}){const[l,u]=V.default.useState(!1),i=()=>u(!0),d=()=>u(!1),f=()=>{n(),d()};return _(N,{children:[t(o.Modal,{overflow:"inside",opened:l,onClose:()=>u(!1),title:`Editing ${r.name}`,trapFocus:!0,onDragStart:h=>{h.stopPropagation()},children:t(mt,{...r,postSubmit:f,styles:s})}),t(o.Button,{size:s.button.size,onClick:i,leftIcon:t(F.Edit,{size:20}),children:"Edit"})]})}function bt({styles:r=L,config:n}){var T,R;te(n);const{data:s=[],loading:l,refresh:u}=W.useRequest(async()=>{const{data:b}=await D.account.list();return b},{refreshDeps:[]}),{data:i=[],loading:d}=W.useRequest(async()=>(await D.role.list()).map(p=>({label:p.name,value:p.id,description:p.description,disabled:p.id===50})),{refreshDeps:[]}),f=K.useMemo(()=>i.reduce((b,p)=>(b.set(p.value,p.label),b),new Map),[i]),h=b=>{var p;return(p=f.get(b))!=null?p:b};return _(N,{children:[t(o.Group,{pt:r.spacing,position:"right",children:t(Re,{onSuccess:u,initialRoleID:(R=(T=i==null?void 0:i[0])==null?void 0:T.value)!=null?R:0})}),_(o.Box,{mt:r.spacing,sx:{position:"relative"},children:[t(o.LoadingOverlay,{visible:l||d}),_(o.Table,{horizontalSpacing:r.spacing,verticalSpacing:r.spacing,fontSize:r.size,highlightOnHover:!0,children:[t("thead",{children:_("tr",{children:[t("th",{children:"Username"}),t("th",{children:"Email"}),t("th",{children:"Role"}),t("th",{children:"Action"})]})}),t("tbody",{children:s.map(b=>{const{id:p,name:j,email:M,role_id:B}=b;return _("tr",{children:[t("td",{width:200,children:j}),t("td",{width:200,children:M}),t("td",{width:200,children:h(B)}),t("td",{width:200,children:_(o.Group,{position:"left",children:[t(vt,{account:b,onSuccess:u}),t(Ce,{id:p,name:j,onSuccess:u})]})})]},p)})})]})]})]})}function wt({postSubmit:r,styles:n=L}){const{control:s,handleSubmit:l}=P.useForm({defaultValues:{name:"",password:""}}),u=async({name:i,password:d})=>{try{C.showNotification({id:"for-login",title:"Pending",message:"Loggin in...",loading:!0});const f=await D.account.login(i,d);window.localStorage.setItem("token",f.token),C.updateNotification({id:"for-login",title:"Successful",message:"Logged in",color:"green"}),r(f)}catch(f){C.updateNotification({id:"for-login",title:"Login Failed",message:f.message,color:"red"})}};return t(o.Box,{mx:"auto",children:_("form",{onSubmit:l(u),children:[t(P.Controller,{name:"name",control:s,render:({field:i})=>t(o.TextInput,{mb:n.spacing,size:n.size,required:!0,label:"Username",...i})}),t(P.Controller,{name:"password",control:s,render:({field:i})=>t(o.PasswordInput,{mb:n.spacing,size:n.size,required:!0,label:"Password",...i})}),t(o.Group,{position:"right",mt:n.spacing,children:t(o.Button,{type:"submit",size:n.button.size,children:"Submit"})})]})})}function _t({styles:r=L,config:n,onSuccess:s}){return te(n),t(N,{children:t(o.Box,{mt:r.spacing,sx:{position:"relative"},children:t(wt,{styles:r,postSubmit:s})})})}const ae={size:"sm",spacing:"md",button:{size:"xs"}};function yt({postSubmit:r,styles:n=ae,initialRoleID:s}){const{control:l,handleSubmit:u}=P.useForm({defaultValues:{name:"",role_id:s}}),i=async({name:d,role_id:f})=>{try{C.showNotification({id:"for-creating",title:"Pending",message:"Adding API Key...",loading:!0});const{app_id:h,app_secret:T}=await D.api_key.create(d,f);C.updateNotification({id:"for-creating",title:"Successful",message:"API Key is added",color:"green"}),r(h,T)}catch(h){C.updateNotification({id:"for-creating",title:"Failed",message:h.message,color:"red"})}};return t(o.Box,{mx:"auto",children:_("form",{onSubmit:u(i),children:[t(P.Controller,{name:"name",control:l,render:({field:d})=>t(o.TextInput,{mb:n.spacing,size:n.size,required:!0,label:"Name",...d})}),t(P.Controller,{name:"role_id",control:l,render:({field:d})=>t(ce,{styles:n,...d})}),t(o.Group,{position:"right",mt:n.spacing,children:t(o.Button,{type:"submit",size:n.button.size,children:"Save"})})]})})}function Te({onSuccess:r,styles:n=ae,initialRoleID:s}){const l=J.useModals(),[u,i]=V.default.useState(!1),d=()=>i(!0),f=()=>i(!1),h=(T,R)=>{f(),l.openModal({title:"API Key is generated",children:_(o.Stack,{children:[t(o.Text,{color:"dimmed",children:"Make sure you save it - you won't be able to access it again."}),t(o.TextInput,{defaultValue:T,disabled:!0,label:"APP ID",styles:{input:{cursor:"text !important"}}}),t(o.TextInput,{defaultValue:R,disabled:!0,label:"APP Secret",styles:{input:{cursor:"text !important"}}}),t(o.Button,{size:"sm",onClick:()=>{J.closeAllModals()},children:"I've saved this API Key"})]}),onClose:()=>{r()}})};return _(N,{children:[t(o.Modal,{overflow:"inside",opened:u,onClose:()=>i(!1),title:"Add an API Key",trapFocus:!0,onDragStart:T=>{T.stopPropagation()},children:t(yt,{postSubmit:h,styles:n,initialRoleID:s})}),t(o.Button,{size:n.button.size,onClick:d,leftIcon:t(F.PlaylistAdd,{size:20}),children:"Add an API Key"})]})}function Ee({id:r,name:n,onSuccess:s,styles:l=ae}){const u=J.useModals(),i=async()=>{if(!!r){C.showNotification({id:"for-deleting",title:"Pending",message:"Deleting API Key...",loading:!0});try{await D.api_key.delete(r),C.updateNotification({id:"for-deleting",title:"Successful",message:`API Key [${n}] is deleted`,color:"green"}),s()}catch(f){C.updateNotification({id:"for-deleting",title:"Failed",message:f.message,color:"red"})}}},d=()=>u.openConfirmModal({title:"Delete this api-key?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:i});return t(o.Button,{size:l.button.size,color:"red",onClick:d,leftIcon:t(F.Trash,{size:20}),children:"Delete"})}function St({styles:r=ae,config:n}){var T,R;te(n);const{data:s=[],loading:l,refresh:u}=W.useRequest(async()=>{const{data:b}=await D.api_key.list();return b},{refreshDeps:[]}),{data:i=[],loading:d}=W.useRequest(async()=>(await D.role.list()).map(p=>({label:p.name,value:p.id,description:p.description,disabled:p.id===50})),{refreshDeps:[]}),f=K.useMemo(()=>i.reduce((b,p)=>(b.set(p.value,p.label),b),new Map),[i]),h=b=>{var p;return(p=f.get(b))!=null?p:b};return _(N,{children:[t(o.Group,{pt:r.spacing,position:"right",children:t(Te,{onSuccess:u,initialRoleID:(R=(T=i==null?void 0:i[0])==null?void 0:T.value)!=null?R:0})}),_(o.Box,{mt:r.spacing,sx:{position:"relative"},children:[t(o.LoadingOverlay,{visible:l||d}),_(o.Table,{horizontalSpacing:r.spacing,verticalSpacing:r.spacing,fontSize:r.size,highlightOnHover:!0,children:[t("thead",{children:_("tr",{children:[t("th",{children:"Name"}),t("th",{children:"APP ID"}),t("th",{children:"Role"}),t("th",{children:"Action"})]})}),t("tbody",{children:s.map(b=>{const{id:p,name:j,app_id:M,role_id:B}=b;return _("tr",{children:[t("td",{width:200,children:j}),t("td",{width:200,children:M}),t("td",{width:200,children:h(B)}),t("td",{width:200,children:t(o.Group,{position:"left",children:t(Ee,{id:p,name:j,onSuccess:u})})})]},p)})})]})]})]})}S.APIKeyList=St,S.AccountList=bt,S.AddAPIKey=Te,S.AddAccount=Re,S.AddDataSource=Se,S.DataSourceList=pt,S.DeleteAPIKey=Ee,S.DeleteAccount=Ce,S.DeleteDataSource=Pe,S.Login=_t,Object.defineProperties(S,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devtable/settings-form",
3
- "version": "5.8.0",
3
+ "version": "5.8.2",
4
4
  "license": "Apache-2.0",
5
5
  "publishConfig": {
6
6
  "access": "public",