@heybejs/core 1.6.0 → 1.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/package.json +1 -1
  2. package/src/db.ts +2 -1
  3. package/src/http/routes/health.ts +9 -0
  4. package/ui/dist/assets/ApplicationPage-DkTYH6WR.js +1 -0
  5. package/ui/dist/assets/AuthCard-wJUv2Sdn.js +1 -0
  6. package/ui/dist/assets/AuthProvidersPage-Bx_JWAxt.js +1 -0
  7. package/ui/dist/assets/BackupsPage-BrFhpIgH.js +1 -0
  8. package/ui/dist/assets/Checkbox-qSXPT8qz.js +1 -0
  9. package/ui/dist/assets/CodeArea-D6AGlQG3.js +34 -0
  10. package/ui/dist/assets/CollectionsLayout-Bqr--gSO.js +8 -0
  11. package/ui/dist/assets/ConfirmEmailChangePage-C5AfNHo0.js +1 -0
  12. package/ui/dist/assets/ConfirmPasswordResetPage-Coe2vuTr.js +1 -0
  13. package/ui/dist/assets/ConfirmVerificationPage-BGX02YAe.js +1 -0
  14. package/ui/dist/assets/CopyButton-WiZL23ED.js +1 -0
  15. package/ui/dist/assets/CronsPage-BVCoYpo1.js +1 -0
  16. package/ui/dist/assets/EmptyState-BNvwv3Xw.js +1 -0
  17. package/ui/dist/assets/ExportPage-BLVcCe2X.js +1 -0
  18. package/ui/dist/assets/ExtensionPage-LezAvM5y.js +1 -0
  19. package/ui/dist/assets/FileField-BIdUasnF.js +1 -0
  20. package/ui/dist/assets/FormFooter-Ct4RFwgS.js +1 -0
  21. package/ui/dist/assets/ImportPage-DDr49aa6.js +1 -0
  22. package/ui/dist/assets/InstallerPage-DEl_f6Iv.js +1 -0
  23. package/ui/dist/assets/InvalidLink-DYrsAHEH.js +1 -0
  24. package/ui/dist/assets/LoginPage-DHnB3eBk.js +1 -0
  25. package/ui/dist/assets/Logo-Dn44Zx6g.js +1 -0
  26. package/ui/dist/assets/LogsPage-BAyH1SUu.js +1 -0
  27. package/ui/dist/assets/MailPage-BbLaQUdV.js +1 -0
  28. package/ui/dist/assets/Match-rL_mIMP3.js +1 -0
  29. package/ui/dist/assets/NumberField-83x9ooVV.js +1 -0
  30. package/ui/dist/assets/OAuth2RedirectPage-BGRd57zj.js +1 -0
  31. package/ui/dist/assets/Page-K-gAWDfu.js +1 -0
  32. package/ui/dist/assets/Popover-ykZ3O0Av.js +1 -0
  33. package/ui/dist/assets/ProviderDialog-DogoekAe.js +1 -0
  34. package/ui/dist/assets/QueryStatus-eTXKeftu.js +1 -0
  35. package/ui/dist/assets/RequestResetPage-CvVIo7hl.js +1 -0
  36. package/ui/dist/assets/{RichTextEditor-1oGZgu61.js → RichTextEditor-Bc3uTBp0.js} +5 -5
  37. package/ui/dist/assets/S3Fields-DejLGW2D.js +1 -0
  38. package/ui/dist/assets/SearchBar-DPaUcuh2.js +1 -0
  39. package/ui/dist/assets/Select-DsX5Ea_q.js +1 -0
  40. package/ui/dist/assets/SettingsLayout-wZHtJg8F.js +1 -0
  41. package/ui/dist/assets/SettingsPage-D8K4z39N.js +1 -0
  42. package/ui/dist/assets/SqlPage-CgdNUnO5.js +1 -0
  43. package/ui/dist/assets/StoragePage-Da-g-Cz5.js +1 -0
  44. package/ui/dist/assets/Switch-Duu2pizo.js +1 -0
  45. package/ui/dist/assets/Table-B0wJiwif.js +1 -0
  46. package/ui/dist/assets/TextField-IItAFjU7.js +1 -0
  47. package/ui/dist/assets/Tooltip-DMaATQZc.js +1 -0
  48. package/ui/dist/assets/atom-CsaMUDV6.js +1 -0
  49. package/ui/dist/assets/check-Dy5JlAkz.js +1 -0
  50. package/ui/dist/assets/chevron-down-CdFqRe9V.js +1 -0
  51. package/ui/dist/assets/clock-CQa7hjXl.js +1 -0
  52. package/ui/dist/assets/context-BLpmYnEM.js +2 -0
  53. package/ui/dist/assets/error-DIHpHIMq.js +1 -0
  54. package/ui/dist/assets/errors-BzXFkL79.js +3 -0
  55. package/ui/dist/assets/field-LSvWL6SU.js +1 -0
  56. package/ui/dist/assets/field-types-DmEN723Z.js +1 -0
  57. package/ui/dist/assets/glass-aa3ISPbD.js +1 -0
  58. package/ui/dist/assets/import-diff-CeufMjY3.js +1 -0
  59. package/ui/dist/assets/index-K3jp0HKn.js +10 -0
  60. package/ui/dist/assets/jwt-DZxaQ4-r.js +1 -0
  61. package/ui/dist/assets/link-IcX1XVhI.js +1 -0
  62. package/ui/dist/assets/preload-helper-DH03enJy.js +1 -0
  63. package/ui/dist/assets/queries-CUkLB99G.js +1 -0
  64. package/ui/dist/assets/search-CViJCnFi.js +1 -0
  65. package/ui/dist/assets/session-oCkjTB0W.js +3 -0
  66. package/ui/dist/assets/settings-Cj7IKVDy.js +1 -0
  67. package/ui/dist/assets/trash-BR5toR-2.js +1 -0
  68. package/ui/dist/assets/use-settings-1G2lnVQh.js +1 -0
  69. package/ui/dist/assets/use-settings-form-DWwEeaUC.js +3 -0
  70. package/ui/dist/assets/useControlledState-jTKE_mWM.js +1 -0
  71. package/ui/dist/assets/useForm-BJzA_-qG.js +1 -0
  72. package/ui/dist/assets/useMatch-CtmIEv-a.js +1 -0
  73. package/ui/dist/assets/useMutation-DQ60EOwe.js +1 -0
  74. package/ui/dist/assets/useNavigate-COQv2_P5.js +1 -0
  75. package/ui/dist/assets/useOverlayState-C6tmr5St.js +1 -0
  76. package/ui/dist/assets/useParams-DGtzGjmL.js +1 -0
  77. package/ui/dist/assets/useQuery-B14t2xNU.js +1 -0
  78. package/ui/dist/assets/useSearch-CNiDThqu.js +1 -0
  79. package/ui/dist/assets/useSelector-CNRxEOGR.js +1 -0
  80. package/ui/dist/assets/useStore-g5QKCOo7.js +1 -0
  81. package/ui/dist/assets/useTopLayer-Dh6x1Bza.js +1 -0
  82. package/ui/dist/assets/with-selector-B7Ab9ZeQ.js +1 -0
  83. package/ui/dist/index.html +33 -2
  84. package/ui/dist/assets/Popover-BKknruJI.js +0 -34
  85. package/ui/dist/assets/index-BrF8ydaD.js +0 -23
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heybejs/core",
3
- "version": "1.6.0",
3
+ "version": "1.6.1",
4
4
  "description": "Open source backend in a single binary: database, auth, file storage, realtime and an admin dashboard. TypeScript on Bun.",
5
5
  "keywords": [
6
6
  "heybe",
package/src/db.ts CHANGED
@@ -62,8 +62,9 @@ function fifoLock(): Lock {
62
62
 
63
63
  function openSqlite(path: string, busyTimeoutMs: number): Database {
64
64
  const sqlite = new Database(path, { create: true, strict: true });
65
- sqlite.run("PRAGMA journal_mode = WAL");
65
+ // first, so the journal mode switch below waits on a lock too instead of failing at once
66
66
  sqlite.run(`PRAGMA busy_timeout = ${busyTimeoutMs}`);
67
+ sqlite.run("PRAGMA journal_mode = WAL");
67
68
  sqlite.run("PRAGMA foreign_keys = ON");
68
69
  sqlite.run("PRAGMA synchronous = NORMAL");
69
70
  // macOS system SQLite defaults to legacy mode, where renames skip views and dropping a column a view reads is allowed
@@ -6,6 +6,15 @@ const PROXY_HEADERS = ["CF-Connecting-IP", "Fly-Client-IP", "X-Forwarded-For"];
6
6
  // PB apis/health.go
7
7
  export function registerHealthRoutes(router: Router): void {
8
8
  router.route("GET", "/api/health", (e) => {
9
+ try {
10
+ e.app.db.get("SELECT 1");
11
+ } catch {
12
+ return e.json(503, {
13
+ message: "Database is not available.",
14
+ code: 503,
15
+ data: {},
16
+ });
17
+ }
9
18
  let data: Record<string, unknown> = {};
10
19
  if (e.hasSuperuserAuth()) {
11
20
  const headers = [
@@ -0,0 +1 @@
1
+ import{t as e}from"./trash-BR5toR-2.js";import{c as t,t as n}from"./errors-BzXFkL79.js";import{r}from"./glass-aa3ISPbD.js";import{t as i}from"./Select-DsX5Ea_q.js";import{n as a,r as o,t as s}from"./Table-B0wJiwif.js";import{t as c}from"./TextField-IItAFjU7.js";import{a as l,d as u,i as d,l as f,o as p,r as m,s as h,t as g,u as _}from"./use-settings-form-DWwEeaUC.js";import{t as v}from"./QueryStatus-eTXKeftu.js";import{t as y}from"./FormFooter-Ct4RFwgS.js";import{t as b}from"./SettingsPage-D8K4z39N.js";import{i as x}from"./use-settings-1G2lnVQh.js";import{a as S}from"./field-LSvWL6SU.js";var C=S();function w(){let e=x();return(0,C.jsx)(b,{title:`Application`,children:e.data?(0,C.jsx)(T,{settings:e.data}):(0,C.jsx)(v,{query:e})})}function T({settings:e}){let{form:t,dirty:r,save:i,submit:a,reset:o}=g(e);return(0,C.jsx)(n,{error:i.error,children:(0,C.jsxs)(`form`,{onSubmit:a,className:`flex flex-col gap-4`,children:[(0,C.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,C.jsx)(t.Field,{name:`settings.meta.appName`,children:e=>(0,C.jsx)(u,{path:`meta.appName`,label:`Application name`,field:e})}),(0,C.jsx)(t.Field,{name:`settings.meta.appURL`,children:e=>(0,C.jsx)(u,{path:`meta.appURL`,label:`Application URL`,field:e})})]}),(0,C.jsx)(t.Field,{name:`settings.meta.hideControls`,children:e=>(0,C.jsx)(_,{path:`meta.hideControls`,label:`Hide collection controls`,field:e})}),(0,C.jsx)(t.Subscribe,{selector:e=>e.values.settings.batch.enabled,children:e=>(0,C.jsx)(f,{errorPrefix:`batch.`,title:`Batch API`,badge:(0,C.jsx)(d,{on:e}),children:(0,C.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,C.jsx)(t.Field,{name:`settings.batch.enabled`,children:e=>(0,C.jsx)(_,{path:`batch.enabled`,label:`Enable batch API`,field:e})}),(0,C.jsx)(t.Field,{name:`settings.batch.maxRequests`,children:e=>(0,C.jsx)(h,{path:`batch.maxRequests`,label:`Max requests`,field:e})}),(0,C.jsx)(t.Field,{name:`settings.batch.timeout`,children:e=>(0,C.jsx)(h,{path:`batch.timeout`,label:`Timeout (seconds)`,field:e})}),(0,C.jsx)(t.Field,{name:`settings.batch.maxBodySize`,children:e=>(0,C.jsx)(h,{path:`batch.maxBodySize`,label:`Max body size (bytes)`,field:e})})]})})}),(0,C.jsx)(t.Subscribe,{selector:e=>e.values.settings.trustedProxy.headers.length>0,children:e=>(0,C.jsx)(f,{errorPrefix:`trustedProxy.`,title:`IP proxy headers`,badge:(0,C.jsx)(d,{on:e}),children:(0,C.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,C.jsx)(t.Field,{name:`settings.trustedProxy.headers`,children:e=>(0,C.jsx)(p,{path:`trustedProxy.headers`,label:`Trusted proxy headers`,hint:`Headers such as X-Forwarded-For.`,field:e})}),(0,C.jsx)(t.Field,{name:`settings.trustedProxy.useLeftmostIP`,children:e=>(0,C.jsx)(_,{path:`trustedProxy.useLeftmostIP`,label:`Use leftmost IP`,field:e})})]})})}),(0,C.jsx)(t.Subscribe,{selector:e=>e.values.settings.rateLimits.enabled,children:e=>(0,C.jsx)(f,{errorPrefix:`rateLimits.`,title:`Rate limiting`,badge:(0,C.jsx)(d,{on:e}),children:(0,C.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,C.jsx)(t.Field,{name:`settings.rateLimits.enabled`,children:e=>(0,C.jsx)(_,{path:`rateLimits.enabled`,label:`Enable rate limits`,field:e})}),(0,C.jsxs)(m,{enabled:e,children:[(0,C.jsx)(t.Field,{name:`settings.rateLimits.rules`,children:e=>(0,C.jsx)(D,{rules:e.state.value,onChange:e.handleChange})}),(0,C.jsx)(t.Field,{name:`settings.rateLimits.excludedIPs`,children:t=>(0,C.jsx)(p,{path:`rateLimits.excludedIPs`,label:`Excluded IPs`,disabled:!e,field:t})})]})]})})}),(0,C.jsx)(t.Subscribe,{selector:e=>e.values.settings.superuserIPs.length>0,children:e=>(0,C.jsx)(f,{errorPrefix:`superuserIPs`,title:`Superuser IPs`,badge:(0,C.jsx)(d,{on:e}),children:(0,C.jsx)(t.Field,{name:`settings.superuserIPs`,children:e=>(0,C.jsx)(p,{path:`superuserIPs`,label:`Allowed IPs`,hint:`Leave empty to allow any IP.`,field:e})})})}),(0,C.jsx)(y,{dirty:r,saving:i.isPending,onReset:o})]})})}var E={label:``,audience:``,duration:1,maxRequests:1};function D({rules:e,onChange:t}){return(0,C.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,C.jsxs)(s,{caption:`Rate limit rules`,children:[(0,C.jsxs)(`colgroup`,{children:[(0,C.jsx)(`col`,{}),(0,C.jsx)(`col`,{className:`w-28`}),(0,C.jsx)(`col`,{className:`w-32`}),(0,C.jsx)(`col`,{className:`w-36`}),(0,C.jsx)(`col`,{className:`w-12`})]}),(0,C.jsx)(`thead`,{children:(0,C.jsxs)(`tr`,{children:[(0,C.jsx)(o,{children:`Label`}),(0,C.jsx)(o,{children:`Audience`}),(0,C.jsx)(o,{children:`Max requests`}),(0,C.jsx)(o,{children:`Duration (seconds)`}),(0,C.jsx)(o,{children:(0,C.jsx)(`span`,{className:`sr-only`,children:`Actions`})})]})}),(0,C.jsx)(`tbody`,{children:e.map((n,r)=>(0,C.jsx)(O,{index:r,rule:n,onChange:n=>t(e.map((e,t)=>t===r?n:e)),onRemove:()=>t(e.filter((e,t)=>t!==r))},r))})]}),(0,C.jsx)(r,{className:`self-start`,onClick:()=>t([...e,{...E}]),children:`Add rule`})]})}function O({index:n,rule:o,onChange:s,onRemove:u}){let d=`rateLimits.rules.${n}`,f=e=>(0,C.jsx)(a,{children:(0,C.jsx)(`div`,{className:`[&_label]:sr-only`,children:e})});return(0,C.jsxs)(`tr`,{children:[f((0,C.jsx)(c,{label:`Label`,value:o.label,error:t(`${d}.label`),onChange:e=>s({...o,label:e.target.value})})),f((0,C.jsxs)(i,{label:`Audience`,value:o.audience,error:t(`${d}.audience`),onChange:e=>s({...o,audience:e.target.value}),children:[(0,C.jsx)(`option`,{value:``,children:`All`}),(0,C.jsx)(`option`,{value:`@guest`,children:`@guest`}),(0,C.jsx)(`option`,{value:`@auth`,children:`@auth`})]})),f((0,C.jsx)(l,{label:`Max requests`,value:o.maxRequests,error:t(`${d}.maxRequests`),onChange:e=>s({...o,maxRequests:e})})),f((0,C.jsx)(l,{label:`Duration (seconds)`,value:o.duration,error:t(`${d}.duration`),onChange:e=>s({...o,duration:e})})),(0,C.jsx)(a,{children:(0,C.jsx)(r,{variant:`ghost`,size:`sm`,"aria-label":`Remove rule ${n+1}`,icon:(0,C.jsx)(e,{size:15,strokeWidth:1.75}),onClick:u})})]})}export{w as ApplicationPage};
@@ -0,0 +1 @@
1
+ import{c as e}from"./errors-BzXFkL79.js";import{t}from"./TextField-IItAFjU7.js";import{t as n}from"./Logo-Dn44Zx6g.js";import{a as r}from"./field-LSvWL6SU.js";var i=r();function a({title:e,children:t}){return(0,i.jsx)(`main`,{className:`flex min-h-dvh items-center justify-center bg-bg p-4`,children:(0,i.jsxs)(`div`,{className:`flex w-full max-w-sm flex-col gap-4 rounded-base border border-line bg-raised p-6`,children:[(0,i.jsx)(n,{size:40}),(0,i.jsx)(`h1`,{className:`text-xl font-semibold`,children:e}),t]})})}function o({path:n,...r}){return(0,i.jsx)(t,{...r,error:e(n)})}export{o as n,a as t};
@@ -0,0 +1 @@
1
+ import{a as e}from"./rolldown-runtime-BWaJ3C7D.js";import{t}from"./useMutation-DQ60EOwe.js";import{E as n,a as r,o as i,r as a}from"./context-BLpmYnEM.js";import{n as o,r as s}from"./glass-aa3ISPbD.js";import{t as c}from"./settings-Cj7IKVDy.js";import{a as l,o as u}from"./field-LSvWL6SU.js";import{i as d}from"./NumberField-83x9ooVV.js";import{t as f}from"./EmptyState-BNvwv3Xw.js";import{t as p}from"./Select-DsX5Ea_q.js";import{t as m}from"./Switch-Duu2pizo.js";import{n as h,t as g}from"./errors-BzXFkL79.js";import{n as _,t as v}from"./queries-CUkLB99G.js";import{c as y,t as b,u as x}from"./ProviderDialog-DogoekAe.js";import{t as S}from"./QueryStatus-eTXKeftu.js";import{t as C}from"./SettingsPage-D8K4z39N.js";var w={name:`power-off`,size:24,node:[[`path`,{d:`M18.36 6.64A9 9 0 0 1 20.77 15`,key:`dxknvb`}],[`path`,{d:`M6.16 6.16a9 9 0 1 0 12.68 12.68`,key:`1x7qb5`}],[`path`,{d:`M12 2v4`,key:`3427ic`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]};w.node;var T=o(w),E=e(u(),1),D=l();function O(){let e=_(),t=e.data?.filter(e=>e.type===`auth`&&e.name!==`_superusers`);return(0,D.jsx)(C,{title:`Auth providers`,children:t?t.length===0?(0,D.jsx)(f,{title:`No auth collections`,children:`Create an auth collection to configure its OAuth2 providers.`}):(0,D.jsx)(k,{collections:t}):(0,D.jsx)(S,{query:e})})}function k({collections:e}){let o=a(),s=n(),c=i(),l=r(),[u,d]=(0,E.useState)((e.find(e=>e.name===`users`)??e[0]).name),[f,_]=(0,E.useState)(null),x=e.find(e=>e.name===u)??e[0],S=x.oauth2,C=S.providers,w=t({mutationFn:e=>o.collections.update(x.id,{oauth2:{...S,...e}}),onSuccess:async()=>{await s.invalidateQueries({queryKey:v.collections}),_(null),l.success(`Auth providers saved.`)}}),T=e=>{w.isPending||w.mutate(e)},O=e=>y.find(t=>t.name===e),k=e=>String(e.displayName||``)||O(e.name)?.displayName||e.name,j=C.map((e,t)=>({provider:e,index:t})),M=y.filter(e=>!C.some(t=>t.name===e.name)),N=async(e,t)=>{await c({title:`Disable ${t}?`,message:`Users will no longer be able to sign in with ${t}.`,confirmLabel:`Disable`,danger:!0})&&T({providers:C.filter((t,n)=>n!==e)})},P=(e,t)=>T({providers:e<C.length?C.map((n,r)=>r===e?t:n):[...C,t]});return(0,D.jsx)(g,{error:w.error,children:(0,D.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[!f&&(0,D.jsx)(h,{}),e.length>1&&(0,D.jsx)(p,{label:`Collection`,value:x.name,onChange:e=>d(e.target.value),children:e.map(e=>(0,D.jsx)(`option`,{value:e.name,children:e.name},e.id))}),(0,D.jsx)(m,{label:`Enable OAuth2`,checked:S.enabled,disabled:w.isPending,onChange:e=>T({enabled:e})}),j.length>0&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`ul`,{"aria-label":`Enabled providers`,className:`grid grid-cols-[repeat(auto-fill,minmax(18rem,1fr))] gap-3`,children:j.map(({provider:e,index:t})=>(0,D.jsx)(A,{name:e.name,label:k(e),status:S.enabled?`Enabled`:`Configured`,onConfigure:()=>_({index:t,provider:e}),onDisable:()=>void N(t,k(e))},e.name))}),(0,D.jsx)(`hr`,{className:`border-line`})]}),(0,D.jsx)(`ul`,{"aria-label":`Other providers`,className:`grid grid-cols-[repeat(auto-fill,minmax(18rem,1fr))] gap-3`,children:M.map(e=>(0,D.jsx)(A,{name:e.name,label:e.displayName,onConfigure:()=>_({index:C.length,provider:{name:e.name}})},e.name))}),f&&(0,D.jsx)(b,{provider:f.provider,errorPath:`oauth2.providers.${f.index}`,onCancel:()=>{_(null),w.reset()},onSave:e=>P(f.index,e),submitLabel:f.index<C.length?`Save changes`:`Create`})]})})}function A({name:e,label:t,status:n,onConfigure:r,onDisable:i}){return(0,D.jsxs)(`li`,{className:`flex items-center gap-3 rounded-base border border-line-strong bg-surface p-3`,children:[(0,D.jsx)(x,{name:e,displayName:t}),(0,D.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,D.jsx)(`span`,{className:`block break-words text-sm text-text`,children:t}),(0,D.jsx)(`span`,{className:`block break-all text-xs text-muted`,children:e})]}),n&&(0,D.jsx)(d,{tone:n===`Enabled`?`success`:`neutral`,children:n}),i&&(0,D.jsx)(s,{variant:`ghost`,size:`sm`,"aria-label":`Disable ${t}`,title:`Disable`,icon:(0,D.jsx)(T,{size:15,strokeWidth:1.75,"aria-hidden":`true`}),onClick:i}),(0,D.jsx)(s,{variant:`ghost`,size:`sm`,"aria-label":`Configure ${t}`,title:`Configure`,icon:(0,D.jsx)(c,{size:15,strokeWidth:1.75,"aria-hidden":`true`}),onClick:r})]})}export{O as AuthProvidersPage};
@@ -0,0 +1 @@
1
+ import{a as e}from"./rolldown-runtime-BWaJ3C7D.js";import{t}from"./error-DIHpHIMq.js";import{t as n}from"./useQuery-B14t2xNU.js";import{E as r,a as i,o as a,r as o,s}from"./context-BLpmYnEM.js";import{t as c}from"./useForm-BJzA_-qG.js";import{a as l,o as u}from"./field-LSvWL6SU.js";import{c as d,n as f,r as p,t as m}from"./errors-BzXFkL79.js";import{t as h}from"./queries-CUkLB99G.js";import{r as g}from"./glass-aa3ISPbD.js";import{t as _}from"./EmptyState-BNvwv3Xw.js";import{t as v}from"./FileField-BIdUasnF.js";import{t as y}from"./Select-DsX5Ea_q.js";import{n as b,r as x,t as S}from"./Table-B0wJiwif.js";import{t as C}from"./TextField-IItAFjU7.js";import{d as w,s as T,t as E}from"./use-settings-form-DWwEeaUC.js";import{t as D}from"./QueryStatus-eTXKeftu.js";import{t as O}from"./FormFooter-Ct4RFwgS.js";import{t as k}from"./SettingsPage-D8K4z39N.js";import{n as A,t as j}from"./S3Fields-DejLGW2D.js";import{i as M}from"./use-settings-1G2lnVQh.js";var N=e(u(),1),P=l();function F({title:e,children:t}){let n=(0,N.useId)();return(0,P.jsxs)(`section`,{"aria-labelledby":n,className:`flex flex-col gap-3`,children:[(0,P.jsx)(`h3`,{id:n,className:`text-sm font-semibold text-text`,children:e}),t]})}function I(e){if(e<1024)return`${e} B`;let t=[`KB`,`MB`,`GB`],n=e,r=-1;do n/=1024,r++;while(n>=1024&&r<t.length-1);return`${n.toFixed(1)} ${t[r]}`}function L(){let e=M();return(0,P.jsx)(k,{title:`Backups`,children:(0,P.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,P.jsx)(R,{}),e.data?(0,P.jsx)(K,{settings:e.data}):(0,P.jsx)(D,{query:e})]})})}function R(){let e=o(),s=r(),c=i(),l=a(),[u,d]=(0,N.useState)(!1),[f,m]=(0,N.useState)(null),y=n({queryKey:h.backups,queryFn:({signal:t})=>e.backups.list({signal:t}).then(e=>e.sort((e,t)=>t.modified.localeCompare(e.modified)))}),C=n({queryKey:h.health,queryFn:({signal:t})=>e.health.check({signal:t}),retry:!1,refetchInterval:e=>e.state.data?.data.canBackup===!1||f&&!f.answered?H:!1}),w=C.data?.data.canBackup===!1;f&&!f.answered&&C.isSuccess&&!w&&C.dataUpdatedAt>f.at+U&&m({...f,answered:!0});let T=()=>Promise.all([s.invalidateQueries({queryKey:h.backups}),s.invalidateQueries({queryKey:h.health})]),[E,O]=(0,N.useState)(!1),k=async t=>{let n=t[0];if(n){O(!0);try{await e.backups.upload(n),c.success(`Backup uploaded.`),await T()}catch(e){c.error(p(e))}finally{O(!1)}}},A=async t=>{try{let n=await e.files.token(),r=document.createElement(`a`);r.href=e.backups.downloadURL(n,t),r.download=t,r.click()}catch(e){c.error(p(e))}},j=async t=>{if(await l({title:`Delete backup`,message:`Delete ${t}? This cannot be undone.`,confirmLabel:`Delete`,danger:!0}))try{await e.backups.delete(t),c.success(`Backup deleted.`),await T()}catch(e){c.error(p(e))}},M=async n=>{if(await l({title:`Restore backup`,message:`Restore ${n}? The current data is replaced and the server restarts.`,confirmLabel:`Restore`,danger:!0,typeToConfirm:n}))try{await e.backups.restore(n),m({at:Date.now(),accepted:!0,answered:!1})}catch(e){e instanceof t&&e.status===0&&!e.isAbort?m({at:Date.now(),accepted:!1,answered:!1}):c.error(p(e))}};return(0,P.jsxs)(F,{title:`Backup files`,children:[f&&(0,P.jsxs)(`div`,{role:`status`,className:`flex items-center gap-3 rounded border border-warning-line bg-warning-bg p-3 text-sm text-warning-text`,children:[(0,P.jsxs)(`p`,{children:[f.accepted?`Restore started. The server restarts with the restored data.`:`The connection was lost, so the restore may not have started.`,f.answered&&` The server is answering again: reload this page and check the data.`]}),(0,P.jsx)(g,{onClick:()=>window.location.reload(),children:`Reload`})]}),(0,P.jsxs)(`div`,{className:`flex flex-col items-start gap-3`,children:[(0,P.jsx)(g,{disabled:w,onClick:()=>d(!0),children:`Create backup`}),(0,P.jsx)(`div`,{className:`w-full`,children:(0,P.jsx)(v,{label:`Backup file`,accept:`.zip`,disabled:E,onChange:e=>void k(e)})}),w&&(0,P.jsx)(`p`,{className:`text-sm`,children:`A backup or restore is already running.`})]}),y.data?y.data.length===0?(0,P.jsx)(_,{title:`No backups yet.`,children:(0,P.jsx)(`p`,{children:`Create a backup or upload a backup file.`})}):(0,P.jsxs)(S,{caption:`Backups`,children:[(0,P.jsx)(`thead`,{children:(0,P.jsxs)(`tr`,{children:[(0,P.jsx)(x,{children:`Name`}),(0,P.jsx)(x,{children:`Size`}),(0,P.jsx)(x,{children:`Modified`}),(0,P.jsx)(x,{children:(0,P.jsx)(`span`,{className:`sr-only`,children:`Actions`})})]})}),(0,P.jsx)(`tbody`,{children:y.data.map(e=>(0,P.jsxs)(`tr`,{children:[(0,P.jsx)(b,{children:e.key}),(0,P.jsx)(b,{children:I(e.size)}),(0,P.jsx)(b,{children:e.modified}),(0,P.jsx)(b,{children:(0,P.jsxs)(`div`,{className:`flex gap-2`,children:[(0,P.jsx)(g,{onClick:()=>void A(e.key),children:`Download`}),(0,P.jsx)(g,{disabled:w,onClick:()=>void M(e.key),children:`Restore`}),(0,P.jsx)(g,{onClick:()=>void j(e.key),children:`Delete`})]})})]},e.key))})]}):(0,P.jsx)(D,{query:y}),u&&(0,P.jsx)(z,{onClose:()=>d(!1),onCreated:()=>void T()})]})}function z({onClose:e,onCreated:t}){let n=o(),r=i(),[a,l]=(0,N.useState)(null),u=c({defaultValues:{name:``},onSubmit:async({value:i})=>{l(null);try{await n.backups.create(i.name||void 0),r.success(`Backup created.`),t(),e()}catch(e){l(e)}}});return(0,P.jsx)(m,{error:a,children:(0,P.jsx)(s,{open:!0,onClose:e,title:`Create backup`,footer:(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(g,{onClick:e,children:`Cancel`}),(0,P.jsx)(u.Subscribe,{selector:e=>e.isSubmitting,children:e=>(0,P.jsx)(g,{type:`submit`,form:`create-backup`,variant:`primary`,loading:e,children:`Create`})})]}),children:(0,P.jsxs)(`form`,{id:`create-backup`,onSubmit:e=>{e.preventDefault(),u.handleSubmit()},className:`flex flex-col gap-3`,children:[(0,P.jsx)(f,{}),(0,P.jsx)(u.Field,{name:`name`,children:e=>(0,P.jsx)(B,{value:e.state.value,onChange:e.handleChange})})]})})})}function B({value:e,onChange:t}){return(0,P.jsx)(C,{label:`Name`,hint:`Lowercase letters, digits, - and _, ending in .zip. Leave empty for a generated name.`,value:e,error:d(`name`),onChange:e=>t(e.target.value)})}var V=[``,`0 0 * * *`,`0 0 * * 0`],H=1e3,U=5e3;function W({field:e}){let t=e.state.value,n=e.handleChange,[r,i]=(0,N.useState)(!1),a=r||!V.includes(t);return(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(G,{value:a?`custom`:t,onChange:e=>{i(e===`custom`),e!==`custom`&&n(e)}}),a&&(0,P.jsx)(w,{path:`backups.cron`,label:`Custom cron expression`,field:e})]})}function G({value:e,onChange:t}){return(0,P.jsxs)(y,{label:`Schedule`,value:e,error:d(`backups.cron`),onChange:e=>t(e.target.value),children:[(0,P.jsx)(`option`,{value:``,children:`Off`}),(0,P.jsx)(`option`,{value:`0 0 * * *`,children:`Every day at 00:00`}),(0,P.jsx)(`option`,{value:`0 0 * * 0`,children:`Every Sunday at 00:00`}),(0,P.jsx)(`option`,{value:`custom`,children:`Custom`})]})}function K({settings:e}){let{form:t,dirty:n,save:r,submit:i,reset:a}=E(e);return(0,P.jsx)(m,{error:r.error,children:(0,P.jsxs)(`form`,{onSubmit:i,className:`flex flex-col gap-4`,children:[(0,P.jsxs)(F,{title:`Automatic backups`,children:[(0,P.jsx)(t.Field,{name:`settings.backups.cron`,children:e=>(0,P.jsx)(W,{field:e})}),(0,P.jsx)(t.Field,{name:`settings.backups.cronMaxKeep`,children:e=>(0,P.jsx)(T,{path:`backups.cronMaxKeep`,label:`Keep the last`,field:e})}),(0,P.jsx)(j,{form:t,prefix:`backups.s3`}),(0,P.jsx)(A,{filesystem:`backups`,disabled:n})]}),(0,P.jsx)(O,{dirty:n,saving:r.isPending,onReset:a})]})})}export{L as BackupsPage};
@@ -0,0 +1 @@
1
+ import{a as e,n as t,r as n}from"./field-LSvWL6SU.js";var r=e();function i({label:e,error:i,hint:a,hideLabel:o,...s}){let{id:c,errorId:l,hintId:u,aria:d}=t({error:i,hint:a});return(0,r.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,r.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,r.jsx)(`input`,{type:`checkbox`,...s,...d,className:`size-4 shrink-0 appearance-none rounded-[4px] border border-field-line bg-field bg-center bg-no-repeat checked:border-accent checked:bg-accent checked:bg-[url(data:image/svg+xml,%3Csvg%20xmlns=%27http://www.w3.org/2000/svg%27%20viewBox=%270%200%2016%2016%27%20fill=%27none%27%20stroke=%27white%27%20stroke-width=%272%27%20stroke-linecap=%27round%27%20stroke-linejoin=%27round%27%3E%3Cpath%20d=%27M3.5%208.5l3%203%206-7%27/%3E%3C/svg%3E)] forced-colors:appearance-auto disabled:opacity-50 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus aria-[invalid=true]:outline-2 aria-[invalid=true]:outline-danger`}),(0,r.jsx)(`label`,{htmlFor:c,className:o?`sr-only`:`text-sm text-text`,children:e})]}),(0,r.jsx)(n,{errorId:l,hintId:u,error:i,hint:a})]})}export{i as t};