@fonderie/react-admin-screens 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // src/screens/AdminShell.tsx
2
2
  import { ConfigEditorScreen, ConfigListScreen } from "@fonderie/react-config-admin-screens";
3
3
  import { TemplateEditorScreen, TemplateListScreen } from "@fonderie/react-courier-admin-screens";
4
- import { useState as useState3 } from "react";
4
+ import { useState as useState4 } from "react";
5
5
 
6
6
  // src/styles.ts
7
7
  var styles = {
@@ -718,8 +718,93 @@ function SubscriberScreen({ client }) {
718
718
  ] });
719
719
  }
720
720
 
721
+ // src/screens/AuditScreen.tsx
722
+ import { useAdminAudit } from "@fonderie/react-admin";
723
+ import { useState as useState3 } from "react";
724
+ import { jsx as jsx11, jsxs as jsxs11 } from "react/jsx-runtime";
725
+ function AuditScreen({ client, pageSize = 50 }) {
726
+ const [draft, setDraft] = useState3({ workspaceId: "", type: "", actorId: "" });
727
+ const [filter, setFilter] = useState3(
728
+ {}
729
+ );
730
+ const { events, hasMore, isLoading, error, refresh, loadMore } = useAdminAudit(client, {
731
+ ...filter,
732
+ limit: pageSize
733
+ });
734
+ const field = (key, placeholder) => /* @__PURE__ */ jsx11(
735
+ "input",
736
+ {
737
+ value: draft[key],
738
+ onChange: (e) => setDraft({ ...draft, [key]: e.target.value }),
739
+ placeholder,
740
+ style: { ...styles.button, cursor: "text" },
741
+ "aria-label": placeholder
742
+ }
743
+ );
744
+ return /* @__PURE__ */ jsxs11("div", { style: styles.container, children: [
745
+ /* @__PURE__ */ jsx11("h1", { style: styles.title, children: "Audit" }),
746
+ /* @__PURE__ */ jsxs11(
747
+ "form",
748
+ {
749
+ style: styles.toolbar,
750
+ onSubmit: (e) => {
751
+ e.preventDefault();
752
+ setFilter({
753
+ ...draft.workspaceId.trim() ? { workspaceId: draft.workspaceId.trim() } : {},
754
+ ...draft.type.trim() ? { type: draft.type.trim() } : {},
755
+ ...draft.actorId.trim() ? { actorId: draft.actorId.trim() } : {}
756
+ });
757
+ },
758
+ children: [
759
+ field("workspaceId", "workspace id (all if empty)"),
760
+ field("type", "event type"),
761
+ field("actorId", "actor id"),
762
+ /* @__PURE__ */ jsx11("button", { type: "submit", style: styles.button, disabled: isLoading, children: "Filter" }),
763
+ /* @__PURE__ */ jsx11(
764
+ "button",
765
+ {
766
+ type: "button",
767
+ style: styles.button,
768
+ onClick: () => void refresh(),
769
+ disabled: isLoading,
770
+ children: "Refresh"
771
+ }
772
+ )
773
+ ]
774
+ }
775
+ ),
776
+ error ? /* @__PURE__ */ jsx11("p", { style: styles.error, role: "alert", children: error.explanation }) : null,
777
+ events.length === 0 && !isLoading ? /* @__PURE__ */ jsx11("p", { style: styles.muted, children: "Nothing recorded for this filter." }) : /* @__PURE__ */ jsxs11("table", { style: styles.table, children: [
778
+ /* @__PURE__ */ jsx11("thead", { children: /* @__PURE__ */ jsxs11("tr", { children: [
779
+ /* @__PURE__ */ jsx11("th", { style: styles.th, children: "When" }),
780
+ /* @__PURE__ */ jsx11("th", { style: styles.th, children: "Type" }),
781
+ /* @__PURE__ */ jsx11("th", { style: styles.th, children: "Workspace" }),
782
+ /* @__PURE__ */ jsx11("th", { style: styles.th, children: "Actor" }),
783
+ /* @__PURE__ */ jsx11("th", { style: styles.th, children: "Request" })
784
+ ] }) }),
785
+ /* @__PURE__ */ jsx11("tbody", { children: events.map((e) => /* @__PURE__ */ jsxs11("tr", { children: [
786
+ /* @__PURE__ */ jsx11("td", { style: { ...styles.td, ...styles.muted }, children: new Date(e.createdAt).toLocaleString() }),
787
+ /* @__PURE__ */ jsx11("td", { style: { ...styles.td, ...styles.mono }, children: e.type }),
788
+ /* @__PURE__ */ jsx11("td", { style: { ...styles.td, ...styles.mono }, children: String(e.payload["workspaceId"] ?? "\u2014") }),
789
+ /* @__PURE__ */ jsx11("td", { style: { ...styles.td, ...styles.mono }, children: e.actorId ?? "\u2014" }),
790
+ /* @__PURE__ */ jsx11("td", { style: { ...styles.td, ...styles.muted }, children: e.requestId ?? "" })
791
+ ] }, e.id)) })
792
+ ] }),
793
+ isLoading ? /* @__PURE__ */ jsx11("p", { style: styles.status, children: "Loading\u2026" }) : null,
794
+ hasMore && !isLoading ? /* @__PURE__ */ jsx11(
795
+ "button",
796
+ {
797
+ type: "button",
798
+ style: { ...styles.button, marginTop: 8 },
799
+ onClick: () => void loadMore(),
800
+ children: "Load more"
801
+ }
802
+ ) : null
803
+ ] });
804
+ }
805
+
721
806
  // src/screens/AdminShell.tsx
722
- import { Fragment as Fragment8, jsx as jsx11, jsxs as jsxs11 } from "react/jsx-runtime";
807
+ import { Fragment as Fragment8, jsx as jsx12, jsxs as jsxs12 } from "react/jsx-runtime";
723
808
  var NAV = [
724
809
  { group: "Today", items: [{ page: "attention", label: "Attention" }] },
725
810
  {
@@ -744,6 +829,7 @@ var NAV = [
744
829
  {
745
830
  group: "Activity",
746
831
  items: [
832
+ { page: "audit", label: "Audit", needs: "audit" },
747
833
  { page: "log", label: "Admin log" },
748
834
  { page: "tokens", label: "Access" }
749
835
  ]
@@ -755,59 +841,64 @@ function AdminShell({
755
841
  courierClient,
756
842
  authClient,
757
843
  billingClient,
844
+ auditClient,
758
845
  environment,
759
846
  page,
760
847
  onNavigate
761
848
  }) {
762
- const [own, setOwn] = useState3("attention");
849
+ const [own, setOwn] = useState4("attention");
763
850
  const current = page ?? own;
764
851
  const go = (p) => {
765
852
  if (onNavigate) onNavigate(p);
766
853
  if (page === void 0) setOwn(p);
767
854
  };
768
- const [editing, setEditing] = useState3(null);
855
+ const [editing, setEditing] = useState4(null);
769
856
  const has = {
770
857
  config: Boolean(configClient),
771
858
  courier: Boolean(courierClient),
772
859
  auth: Boolean(authClient),
773
- billing: Boolean(billingClient)
860
+ billing: Boolean(billingClient),
861
+ audit: Boolean(auditClient)
774
862
  };
775
863
  let body;
776
864
  switch (current) {
777
865
  case "attention":
778
- body = /* @__PURE__ */ jsx11(AttentionScreen, { client });
866
+ body = /* @__PURE__ */ jsx12(AttentionScreen, { client });
779
867
  break;
780
868
  case "modules":
781
- body = /* @__PURE__ */ jsx11(ModulesScreen, { client });
869
+ body = /* @__PURE__ */ jsx12(ModulesScreen, { client });
782
870
  break;
783
871
  case "doctor":
784
- body = /* @__PURE__ */ jsx11(DoctorScreen, { client });
872
+ body = /* @__PURE__ */ jsx12(DoctorScreen, { client });
785
873
  break;
786
874
  case "config":
787
- body = /* @__PURE__ */ jsx11(ConfigScreen, { client });
875
+ body = /* @__PURE__ */ jsx12(ConfigScreen, { client });
788
876
  break;
789
877
  case "routes":
790
- body = /* @__PURE__ */ jsx11(RoutesScreen, { client });
878
+ body = /* @__PURE__ */ jsx12(RoutesScreen, { client });
791
879
  break;
792
880
  case "tokens":
793
- body = /* @__PURE__ */ jsx11(TokensScreen, { client });
881
+ body = /* @__PURE__ */ jsx12(TokensScreen, { client });
794
882
  break;
795
883
  case "log":
796
- body = /* @__PURE__ */ jsx11(AdminLogScreen, { client });
884
+ body = /* @__PURE__ */ jsx12(AdminLogScreen, { client });
797
885
  break;
798
886
  case "catalog":
799
- body = billingClient ? /* @__PURE__ */ jsx11(CatalogScreen, { client: billingClient }) : /* @__PURE__ */ jsx11("p", { style: styles.status, children: "Pass a BillingAdminClient to see the catalog here." });
887
+ body = billingClient ? /* @__PURE__ */ jsx12(CatalogScreen, { client: billingClient }) : /* @__PURE__ */ jsx12("p", { style: styles.status, children: "Pass a BillingAdminClient to see the catalog here." });
800
888
  break;
801
889
  case "subscriber":
802
- body = billingClient ? /* @__PURE__ */ jsx11(SubscriberScreen, { client: billingClient }) : /* @__PURE__ */ jsx11("p", { style: styles.status, children: "Pass a BillingAdminClient to look up subscribers here." });
890
+ body = billingClient ? /* @__PURE__ */ jsx12(SubscriberScreen, { client: billingClient }) : /* @__PURE__ */ jsx12("p", { style: styles.status, children: "Pass a BillingAdminClient to look up subscribers here." });
891
+ break;
892
+ case "audit":
893
+ body = auditClient ? /* @__PURE__ */ jsx12(AuditScreen, { client: auditClient }) : /* @__PURE__ */ jsx12("p", { style: styles.status, children: "Pass an AuditAdminClient to see the audit trail here." });
803
894
  break;
804
895
  case "users":
805
- body = authClient ? /* @__PURE__ */ jsx11(UsersScreen, { client: authClient }) : /* @__PURE__ */ jsx11("p", { style: styles.status, children: "Pass an AuthAdminClient to look up users here." });
896
+ body = authClient ? /* @__PURE__ */ jsx12(UsersScreen, { client: authClient }) : /* @__PURE__ */ jsx12("p", { style: styles.status, children: "Pass an AuthAdminClient to look up users here." });
806
897
  break;
807
898
  case "settings":
808
- body = !configClient ? /* @__PURE__ */ jsx11("p", { style: styles.status, children: "Pass a ConfigAdminClient to manage config and secrets here." }) : editing && editing.kind !== "template" ? /* @__PURE__ */ jsxs11(Fragment8, { children: [
809
- /* @__PURE__ */ jsx11("button", { type: "button", style: styles.button, onClick: () => setEditing(null), children: "\u2190 Back" }),
810
- /* @__PURE__ */ jsx11(
899
+ body = !configClient ? /* @__PURE__ */ jsx12("p", { style: styles.status, children: "Pass a ConfigAdminClient to manage config and secrets here." }) : editing && editing.kind !== "template" ? /* @__PURE__ */ jsxs12(Fragment8, { children: [
900
+ /* @__PURE__ */ jsx12("button", { type: "button", style: styles.button, onClick: () => setEditing(null), children: "\u2190 Back" }),
901
+ /* @__PURE__ */ jsx12(
811
902
  ConfigEditorScreen,
812
903
  {
813
904
  client: configClient,
@@ -817,7 +908,7 @@ function AdminShell({
817
908
  onSaved: () => setEditing(null)
818
909
  }
819
910
  )
820
- ] }) : /* @__PURE__ */ jsx11(
911
+ ] }) : /* @__PURE__ */ jsx12(
821
912
  ConfigListScreen,
822
913
  {
823
914
  client: configClient,
@@ -828,9 +919,9 @@ function AdminShell({
828
919
  );
829
920
  break;
830
921
  case "templates":
831
- body = !courierClient ? /* @__PURE__ */ jsx11("p", { style: styles.status, children: "Pass a CourierAdminClient to manage templates here." }) : editing?.kind === "template" ? /* @__PURE__ */ jsxs11(Fragment8, { children: [
832
- /* @__PURE__ */ jsx11("button", { type: "button", style: styles.button, onClick: () => setEditing(null), children: "\u2190 Back" }),
833
- /* @__PURE__ */ jsx11(
922
+ body = !courierClient ? /* @__PURE__ */ jsx12("p", { style: styles.status, children: "Pass a CourierAdminClient to manage templates here." }) : editing?.kind === "template" ? /* @__PURE__ */ jsxs12(Fragment8, { children: [
923
+ /* @__PURE__ */ jsx12("button", { type: "button", style: styles.button, onClick: () => setEditing(null), children: "\u2190 Back" }),
924
+ /* @__PURE__ */ jsx12(
834
925
  TemplateEditorScreen,
835
926
  {
836
927
  client: courierClient,
@@ -838,7 +929,7 @@ function AdminShell({
838
929
  onSaved: () => setEditing(null)
839
930
  }
840
931
  )
841
- ] }) : /* @__PURE__ */ jsx11(
932
+ ] }) : /* @__PURE__ */ jsx12(
842
933
  TemplateListScreen,
843
934
  {
844
935
  client: courierClient,
@@ -847,13 +938,13 @@ function AdminShell({
847
938
  );
848
939
  break;
849
940
  }
850
- return /* @__PURE__ */ jsxs11("div", { style: styles.shell, children: [
851
- /* @__PURE__ */ jsx11("nav", { style: styles.nav, "aria-label": "Admin", children: NAV.map((g) => {
941
+ return /* @__PURE__ */ jsxs12("div", { style: styles.shell, children: [
942
+ /* @__PURE__ */ jsx12("nav", { style: styles.nav, "aria-label": "Admin", children: NAV.map((g) => {
852
943
  const items = g.items.filter((i) => !i.needs || has[i.needs]);
853
944
  if (items.length === 0) return null;
854
- return /* @__PURE__ */ jsxs11("div", { children: [
855
- /* @__PURE__ */ jsx11("div", { style: styles.navGroup, children: g.group }),
856
- items.map((i) => /* @__PURE__ */ jsx11(
945
+ return /* @__PURE__ */ jsxs12("div", { children: [
946
+ /* @__PURE__ */ jsx12("div", { style: styles.navGroup, children: g.group }),
947
+ items.map((i) => /* @__PURE__ */ jsx12(
857
948
  "button",
858
949
  {
859
950
  type: "button",
@@ -869,13 +960,14 @@ function AdminShell({
869
960
  ))
870
961
  ] }, g.group);
871
962
  }) }),
872
- /* @__PURE__ */ jsx11("main", { style: styles.main, children: body })
963
+ /* @__PURE__ */ jsx12("main", { style: styles.main, children: body })
873
964
  ] });
874
965
  }
875
966
  export {
876
967
  AdminLogScreen,
877
968
  AdminShell,
878
969
  AttentionScreen,
970
+ AuditScreen,
879
971
  CatalogScreen,
880
972
  ConfigScreen,
881
973
  DoctorScreen,