@rebasepro/admin 0.9.1-canary.16c42e9 → 0.9.1-canary.26fe4b2

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 (92) hide show
  1. package/dist/{CollectionEditorDialog-DbPpDDwb.js → CollectionEditorDialog-BOlKGGg7.js} +123 -31
  2. package/dist/{CollectionEditorDialog-DbPpDDwb.js.map → CollectionEditorDialog-BOlKGGg7.js.map} +1 -1
  3. package/dist/{PropertyEditView-DfJbZ67t.js → PropertyEditView-i51tFOfM.js} +3 -3
  4. package/dist/PropertyEditView-i51tFOfM.js.map +1 -0
  5. package/dist/{RouterCollectionsStudioView-C6XQ7Il5.js → RouterCollectionsStudioView-Dh4W53PU.js} +4 -4
  6. package/dist/{RouterCollectionsStudioView-C6XQ7Il5.js.map → RouterCollectionsStudioView-Dh4W53PU.js.map} +1 -1
  7. package/dist/collection_editor_ui.js +4 -4
  8. package/dist/components/field_configs.d.ts +17 -0
  9. package/dist/contexts/BreacrumbsContext.d.ts +1 -1
  10. package/dist/editor.js.map +1 -1
  11. package/dist/export-BM6HPujv.js +518 -0
  12. package/dist/export-BM6HPujv.js.map +1 -0
  13. package/dist/{history-GSa4BgDt.js → history-CtIPJxvQ.js} +3 -3
  14. package/dist/history-CtIPJxvQ.js.map +1 -0
  15. package/dist/hooks/useSelectionDialog.d.ts +1 -1
  16. package/dist/import-DzQnT03v.js +328 -0
  17. package/dist/import-DzQnT03v.js.map +1 -0
  18. package/dist/index.js +3299 -1
  19. package/dist/index.js.map +1 -0
  20. package/dist/preview/components/UrlComponentPreview.d.ts +2 -1
  21. package/dist/preview/util.d.ts +1 -0
  22. package/dist/util/view_mode.d.ts +54 -0
  23. package/dist/{src-B8WuGSPZ.js → util-XFwQ9FEc.js} +17388 -21329
  24. package/dist/util-XFwQ9FEc.js.map +1 -0
  25. package/package.json +8 -8
  26. package/src/collection_editor/ui/collection_editor/CollectionRLSTab.tsx +104 -9
  27. package/src/collection_editor/ui/collection_editor/properties/CommonPropertyFields.tsx +1 -1
  28. package/src/collection_editor/ui/collection_editor/properties/EnumPropertyField.tsx +1 -1
  29. package/src/components/CollectionTableBinding/CollectionRowActions.tsx +1 -1
  30. package/src/components/CollectionTableBinding/fields/TableReferenceField.tsx +1 -1
  31. package/src/components/CollectionViewBinding/CollectionBoardViewBinding.tsx +1 -1
  32. package/src/components/CollectionViewBinding/CollectionViewActions.tsx +1 -1
  33. package/src/components/CollectionViewBinding/CollectionViewBinding.tsx +76 -126
  34. package/src/components/CollectionViewBinding/CollectionViewStartActions.tsx +4 -8
  35. package/src/components/CollectionViewBinding/SplitListView.tsx +114 -63
  36. package/src/components/DetailViewBinding.tsx +4 -2
  37. package/src/components/EditFormActions.tsx +2 -2
  38. package/src/components/EditViewBinding.tsx +3 -2
  39. package/src/components/EntityPreviewBinding.tsx +2 -1
  40. package/src/components/HomePage/ContentHomePage.tsx +2 -1
  41. package/src/components/HomePage/FavouritesView.tsx +1 -1
  42. package/src/components/RebaseRouteDefs.tsx +1 -1
  43. package/src/components/ReferenceTable/SelectionTableBinding.tsx +2 -1
  44. package/src/components/ReferenceWidget.tsx +1 -1
  45. package/src/components/SelectableTable/filters/ReferenceFilterField.tsx +1 -1
  46. package/src/components/SidePanelBinding.tsx +46 -8
  47. package/src/components/SidePanelProvider.tsx +14 -11
  48. package/src/components/field_configs.tsx +41 -24
  49. package/src/components/history/EntityHistoryView.tsx +1 -1
  50. package/src/contexts/BreacrumbsContext.tsx +1 -1
  51. package/src/data_import/components/ImportNewPropertyFieldPreview.tsx +2 -4
  52. package/src/data_import/import/ImportCollectionAction.tsx +6 -6
  53. package/src/editor/selectors/color-selector.tsx +1 -1
  54. package/src/editor/selectors/node-selector.tsx +1 -1
  55. package/src/editor/selectors/text-buttons.tsx +1 -1
  56. package/src/form/EntityForm.tsx +4 -1
  57. package/src/form/EntityFormBinding.tsx +3 -1
  58. package/src/form/field_bindings/ArrayCustomShapedFieldBinding.tsx +2 -1
  59. package/src/form/field_bindings/ArrayOfReferencesFieldBinding.tsx +3 -2
  60. package/src/form/field_bindings/BlockFieldBinding.tsx +2 -1
  61. package/src/form/field_bindings/DateTimeFieldBinding.tsx +2 -1
  62. package/src/form/field_bindings/KeyValueFieldBinding.tsx +2 -1
  63. package/src/form/field_bindings/MapFieldBinding.tsx +2 -1
  64. package/src/form/field_bindings/MarkdownEditorFieldBinding.tsx +2 -1
  65. package/src/form/field_bindings/MultiSelectFieldBinding.tsx +2 -1
  66. package/src/form/field_bindings/MultipleRelationFieldBinding.tsx +2 -1
  67. package/src/form/field_bindings/ReadOnlyFieldBinding.tsx +2 -1
  68. package/src/form/field_bindings/ReferenceFieldBinding.tsx +3 -2
  69. package/src/form/field_bindings/RelationFieldBinding.tsx +2 -1
  70. package/src/form/field_bindings/RepeatFieldBinding.tsx +2 -1
  71. package/src/form/field_bindings/SelectFieldBinding.tsx +2 -1
  72. package/src/form/field_bindings/StorageUploadFieldBinding.tsx +2 -1
  73. package/src/form/field_bindings/SwitchFieldBinding.tsx +2 -1
  74. package/src/form/field_bindings/TextFieldBinding.tsx +2 -1
  75. package/src/form/field_bindings/UserSelectFieldBinding.tsx +2 -1
  76. package/src/form/field_bindings/VectorFieldBinding.tsx +2 -1
  77. package/src/hooks/useBuildSidePanel.tsx +8 -0
  78. package/src/hooks/useSelectionDialog.tsx +3 -3
  79. package/src/preview/components/ImagePreview.tsx +1 -1
  80. package/src/preview/components/ReferencePreview.tsx +1 -1
  81. package/src/preview/components/RelationPreview.tsx +2 -2
  82. package/src/preview/components/UrlComponentPreview.tsx +2 -9
  83. package/src/preview/property_previews/ArrayOfStringsPreview.tsx +1 -1
  84. package/src/preview/property_previews/NumberPropertyPreview.tsx +1 -1
  85. package/src/preview/util.ts +9 -0
  86. package/src/routes/CustomViewRoute.tsx +2 -1
  87. package/src/routes/RebaseRoute.tsx +20 -25
  88. package/src/util/navigation_utils.ts +2 -5
  89. package/src/util/view_mode.ts +102 -0
  90. package/dist/PropertyEditView-DfJbZ67t.js.map +0 -1
  91. package/dist/history-GSa4BgDt.js.map +0 -1
  92. package/dist/src-B8WuGSPZ.js.map +0 -1
@@ -1,18 +1,18 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
2
- import { At as useImportConfig, Bn as useUrlController, Bt as getFieldId, Ct as useCollectionEditorController, Et as convertDataToEntity, Ft as PropertyConfigBadge, Hn as useNavigationStateController, Mt as ImportFileUpload, Qn as CollectionTableBinding, Tt as DataNewPropertiesMapping, Wn as useCollectionRegistryController, Xn as useSelectionController, dn as SearchIconsView, fn as FieldCaption, h as toSerializableCollectionConfig, i as namespaceToPropertiesOrderPath, jt as ImportSaveInProgress, kt as getInferenceType, n as getFullIdPath, r as idToPropertiesPath, s as CollectionGenerationApiError, t as getFullId, u as validateCollectionJson, v as useCollectionsConfigController, wt as ImportNewPropertyFieldPreview, zt as getFieldConfig } from "./src-B8WuGSPZ.js";
3
- import { a as updatePropertyFromWidget, c as useAIModifiedPaths, i as supportedFields, l as useSafeSnackbarController, n as PropertyForm, o as PropertyTree, r as PropertyFormDialog, s as AIModifiedPathsProvider } from "./PropertyEditView-DfJbZ67t.js";
2
+ import { Dt as ImportSaveInProgress, Et as useImportConfig, Mt as PropertyConfigBadge, Nn as useCollectionRegistryController, Nt as SearchIconsView, O as getFieldConfig, Ot as ImportFileUpload, Pt as FieldCaption, Qt as CollectionTableBinding, St as convertDataToEntity, Tt as getInferenceType, Xt as useSelectionController, _t as useCollectionEditorController, an as useNavigationStateController, bt as ImportNewPropertyFieldPreview, g as useCollectionsConfigController, i as namespaceToPropertiesOrderPath, k as getFieldId, l as validateCollectionJson, n as getFullIdPath, o as CollectionGenerationApiError, p as toSerializableCollectionConfig, r as idToPropertiesPath, rn as useUrlController, t as getFullId, xt as DataNewPropertiesMapping } from "./util-XFwQ9FEc.js";
3
+ import { a as updatePropertyFromWidget, c as useAIModifiedPaths, i as supportedFields, l as useSafeSnackbarController, n as PropertyForm, o as PropertyTree, r as PropertyFormDialog, s as AIModifiedPathsProvider } from "./PropertyEditView-i51tFOfM.js";
4
4
  import * as React$1 from "react";
5
5
  import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
6
6
  import { Alert, AppWindow, ArrowLeftIcon, BooleanSwitchWithLabel, Button, Card, CheckIcon, Chip, CircularProgress, CircularProgressCenter, CodeIcon, ColumnsIcon, Container, CopyIcon, DebouncedTextField, Dialog, DialogActions, DialogContent, DialogTitle, ErrorBoundary, FileIcon, FileSearchIcon, FileTextIcon, IconButton, KanbanIcon, KeyIcon, LayoutGridIcon, ListIcon, LoadingButton, Menu, MultiSelect, MultiSelectItem, PanelLeftIcon, Paper, PlusIcon, Select, SelectItem, ShoppingCartIcon, SquareIcon, Tab, TableIcon, Tabs, TextField, ToggleButtonGroup, Tooltip, Trash2Icon, Typography, UserIcon, XIcon, cls, coolIconKeys, defaultBorderMixin, iconSize } from "@rebasepro/ui";
7
7
  import { getEffectiveSecurityRules, getSubcollections, getTableName, isPropertyBuilder, removeInitialAndTrailingSlashes } from "@rebasepro/common";
8
8
  import { AIIcon, ConfirmationDialog, ErrorView, IconForView, UnsavedChangesDialog, useAuthController, useCustomizationController, useLargeLayout, useRebaseContext, useUnsavedChangesDialog } from "@rebasepro/app";
9
9
  import { Field, Formex, clone, getIn, useCreateFormex, useFormex } from "@rebasepro/forms";
10
- import { z } from "zod";
10
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
11
11
  import { camelCase, getPolicyNamesForRule, getPolicyNamesForRules, isEmptyObject, mergeDeep, prettifyIdentifier, randomString, removeUndefined, singular, slugify, toSnakeCase, unslugify } from "@rebasepro/utils";
12
12
  import { getDataSourceCapabilities } from "@rebasepro/types";
13
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
14
- import { Highlight, themes } from "prism-react-renderer";
13
+ import { z } from "zod";
15
14
  import { buildEntityPropertiesFromData, buildPropertyFromData } from "@rebasepro/inference";
15
+ import { Highlight, themes } from "prism-react-renderer";
16
16
  import JSON5 from "json5";
17
17
  //#region src/collection_editor/ui/collection_editor/CollectionYupValidation.tsx
18
18
  var CollectionEditorSchema = z.object({
@@ -2381,6 +2381,38 @@ function CollectionRLSTab() {
2381
2381
  values.table,
2382
2382
  values.alias
2383
2383
  ]);
2384
+ /**
2385
+ * Application roles available to `SecurityRule.roles`.
2386
+ *
2387
+ * Deliberately NOT `fetchAvailableRoles` — that returns native pg_roles
2388
+ * (postgres, rebase_user, …), which can never satisfy an application-role
2389
+ * condition.
2390
+ */
2391
+ const [availableRoles, setAvailableRoles] = useState([]);
2392
+ const [rolesUnavailable, setRolesUnavailable] = useState(false);
2393
+ useEffect(() => {
2394
+ let mounted = true;
2395
+ const fetchRoles = async () => {
2396
+ if (!databaseAdmin?.fetchApplicationRoles) {
2397
+ if (mounted) setRolesUnavailable(true);
2398
+ return;
2399
+ }
2400
+ try {
2401
+ const fetched = await databaseAdmin.fetchApplicationRoles();
2402
+ if (mounted) {
2403
+ setAvailableRoles(fetched);
2404
+ setRolesUnavailable(false);
2405
+ }
2406
+ } catch (e) {
2407
+ console.error("Failed to fetch application roles", e);
2408
+ if (mounted) setRolesUnavailable(true);
2409
+ }
2410
+ };
2411
+ fetchRoles();
2412
+ return () => {
2413
+ mounted = false;
2414
+ };
2415
+ }, [databaseAdmin]);
2384
2416
  const tableName = values.id || values.table || values.alias;
2385
2417
  /**
2386
2418
  * Every policy name `rebase db push` would write for this collection.
@@ -2483,7 +2515,7 @@ function CollectionRLSTab() {
2483
2515
  tablename: values.id || values.table || values.alias || "your_table",
2484
2516
  permissive: (rule.mode || "permissive").toUpperCase(),
2485
2517
  cmd: (rule.operation || "ALL").toUpperCase(),
2486
- roles: rule.roles || ["public"],
2518
+ roles: rule.roles || [],
2487
2519
  qual: rule.using || null,
2488
2520
  with_check: rule.withCheck || null
2489
2521
  }),
@@ -2588,6 +2620,8 @@ function CollectionRLSTab() {
2588
2620
  children: editingPolicy && /* @__PURE__ */ jsx(InlinePolicyEditor, {
2589
2621
  policy: editingPolicy === "new" ? void 0 : editingPolicy,
2590
2622
  table: values.id || values.table || values.alias || "your_table",
2623
+ availableRoles,
2624
+ rolesUnavailable,
2591
2625
  onSave: handleSave,
2592
2626
  onCancel: () => setEditingPolicy(null)
2593
2627
  })
@@ -2602,20 +2636,31 @@ var COMMAND_OPTIONS = [
2602
2636
  "UPDATE",
2603
2637
  "DELETE"
2604
2638
  ];
2605
- var ROLE_OPTIONS = [
2606
- "public",
2607
- "authenticated",
2608
- "anon",
2609
- "admin"
2610
- ];
2611
- function InlinePolicyEditor({ policy, table, onSave, onCancel }) {
2639
+ function InlinePolicyEditor({ policy, table, availableRoles, rolesUnavailable, onSave, onCancel }) {
2612
2640
  const [name, setName] = useState(policy?.policyname || "");
2613
2641
  const [behavior, setBehavior] = useState(policy?.permissive || "PERMISSIVE");
2614
2642
  const [command, setCommand] = useState(policy?.cmd || "ALL");
2615
- const [roles, setRoles] = useState(policy?.roles ? Array.isArray(policy.roles) ? policy.roles : [policy.roles] : ["public"]);
2643
+ const [roles, setRoles] = useState(policy?.roles ? Array.isArray(policy.roles) ? policy.roles : [policy.roles] : []);
2644
+ const [customRole, setCustomRole] = useState("");
2616
2645
  const [usingExpr, setUsingExpr] = useState(policy?.qual || "");
2617
2646
  const [checkExpr, setCheckExpr] = useState(policy?.with_check || "");
2618
2647
  const showCheck = command === "ALL" || command === "INSERT" || command === "UPDATE";
2648
+ /**
2649
+ * Roles offered in the dropdown: those in use in the project, plus any the
2650
+ * rule already carries. The union matters — application roles are derived
2651
+ * from what users hold, so a role that is referenced here but assigned to
2652
+ * nobody would otherwise vanish from its own policy on the next save.
2653
+ */
2654
+ const roleOptions = useMemo(() => Array.from(new Set([...availableRoles, ...roles])).sort(), [availableRoles, roles]);
2655
+ const addCustomRole = () => {
2656
+ const trimmed = customRole.trim();
2657
+ if (!trimmed || roles.includes(trimmed)) {
2658
+ setCustomRole("");
2659
+ return;
2660
+ }
2661
+ setRoles([...roles, trimmed]);
2662
+ setCustomRole("");
2663
+ };
2619
2664
  return /* @__PURE__ */ jsxs(Fragment, { children: [
2620
2665
  /* @__PURE__ */ jsxs(DialogTitle, {
2621
2666
  variant: "h6",
@@ -2685,20 +2730,67 @@ function InlinePolicyEditor({ policy, table, onSave, onCancel }) {
2685
2730
  }),
2686
2731
  /* @__PURE__ */ jsxs("div", {
2687
2732
  className: "flex flex-col gap-1.5",
2688
- children: [/* @__PURE__ */ jsx(Typography, {
2689
- variant: "caption",
2690
- className: "uppercase tracking-wider text-text-secondary",
2691
- children: "Target Roles"
2692
- }), /* @__PURE__ */ jsx(MultiSelect, {
2693
- size: "small",
2694
- value: roles,
2695
- onValueChange: setRoles,
2696
- placeholder: "Select roles",
2697
- children: ROLE_OPTIONS.map((r) => /* @__PURE__ */ jsx(MultiSelectItem, {
2698
- value: r,
2699
- children: r
2700
- }, r))
2701
- })]
2733
+ children: [
2734
+ /* @__PURE__ */ jsx(Typography, {
2735
+ variant: "caption",
2736
+ className: "uppercase tracking-wider text-text-secondary",
2737
+ children: "Application Roles"
2738
+ }),
2739
+ /* @__PURE__ */ jsxs(Typography, {
2740
+ variant: "caption",
2741
+ className: "text-text-secondary opacity-80 -mt-1",
2742
+ children: [
2743
+ "Roles held by users of this project, matched via ",
2744
+ /* @__PURE__ */ jsx("span", {
2745
+ className: "font-mono",
2746
+ children: "auth.roles()"
2747
+ }),
2748
+ ". These are not PostgreSQL roles — leave empty to apply the policy to everyone."
2749
+ ]
2750
+ }),
2751
+ roleOptions.length > 0 && /* @__PURE__ */ jsx(MultiSelect, {
2752
+ size: "small",
2753
+ value: roles,
2754
+ onValueChange: setRoles,
2755
+ placeholder: "Select roles",
2756
+ children: roleOptions.map((r) => /* @__PURE__ */ jsx(MultiSelectItem, {
2757
+ value: r,
2758
+ children: r
2759
+ }, r))
2760
+ }),
2761
+ rolesUnavailable && roleOptions.length === 0 && /* @__PURE__ */ jsx(Typography, {
2762
+ variant: "caption",
2763
+ className: "text-text-secondary opacity-80",
2764
+ children: "Could not load the project's roles — enter them manually below."
2765
+ }),
2766
+ !rolesUnavailable && roleOptions.length === 0 && /* @__PURE__ */ jsx(Typography, {
2767
+ variant: "caption",
2768
+ className: "text-text-secondary opacity-80",
2769
+ children: "No roles are assigned to any user yet — enter one manually below."
2770
+ }),
2771
+ /* @__PURE__ */ jsxs("div", {
2772
+ className: "flex gap-2 items-center",
2773
+ children: [/* @__PURE__ */ jsx(TextField, {
2774
+ size: "small",
2775
+ value: customRole,
2776
+ onChange: (e) => setCustomRole(e.target.value),
2777
+ onKeyDown: (e) => {
2778
+ if (e.key === "Enter") {
2779
+ e.preventDefault();
2780
+ addCustomRole();
2781
+ }
2782
+ },
2783
+ placeholder: "Add a role not listed, e.g. editor"
2784
+ }), /* @__PURE__ */ jsx(Button, {
2785
+ size: "small",
2786
+ variant: "outlined",
2787
+ color: "neutral",
2788
+ disabled: !customRole.trim(),
2789
+ onClick: addCustomRole,
2790
+ children: "Add"
2791
+ })]
2792
+ })
2793
+ ]
2702
2794
  }),
2703
2795
  command !== "INSERT" && /* @__PURE__ */ jsxs("div", {
2704
2796
  className: "flex flex-col gap-1.5",
@@ -2709,7 +2801,7 @@ function InlinePolicyEditor({ policy, table, onSave, onCancel }) {
2709
2801
  }), /* @__PURE__ */ jsx(TextField, {
2710
2802
  value: usingExpr,
2711
2803
  onChange: (e) => setUsingExpr(e.target.value),
2712
- placeholder: "e.g. auth.uid() = user_id"
2804
+ placeholder: "e.g. auth.uid() = uid"
2713
2805
  })]
2714
2806
  }),
2715
2807
  showCheck && /* @__PURE__ */ jsxs("div", {
@@ -2721,7 +2813,7 @@ function InlinePolicyEditor({ policy, table, onSave, onCancel }) {
2721
2813
  }), /* @__PURE__ */ jsx(TextField, {
2722
2814
  value: checkExpr,
2723
2815
  onChange: (e) => setCheckExpr(e.target.value),
2724
- placeholder: "e.g. auth.uid() = user_id"
2816
+ placeholder: "e.g. auth.uid() = uid"
2725
2817
  })]
2726
2818
  })
2727
2819
  ]
@@ -3649,4 +3741,4 @@ var validateId = (value, isNewCollection, existingPaths, existingIds) => {
3649
3741
  //#endregion
3650
3742
  export { CollectionEditorDialog as n, CollectionEditorDialog_exports as r, CollectionEditor as t };
3651
3743
 
3652
- //# sourceMappingURL=CollectionEditorDialog-DbPpDDwb.js.map
3744
+ //# sourceMappingURL=CollectionEditorDialog-BOlKGGg7.js.map