@constructive-io/schema-builder 0.2.0 → 0.2.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.
- package/CHANGELOG.md +11 -0
- package/dist/card-widths-CmIxkRfh.cjs +28 -0
- package/dist/card-widths-CmIxkRfh.cjs.map +1 -0
- package/dist/card-widths-pI4Kw4Xz.js +22 -0
- package/dist/card-widths-pI4Kw4Xz.js.map +1 -0
- package/dist/core-WwCS0CKu.cjs +66 -0
- package/dist/core-WwCS0CKu.cjs.map +1 -0
- package/dist/core-kx6KjxE5.js +49 -0
- package/dist/core-kx6KjxE5.js.map +1 -0
- package/dist/core.cjs +14 -212
- package/dist/core.d.cts +3 -54
- package/dist/core.d.ts +3 -54
- package/dist/core.js +3 -200
- package/dist/create-table-card-BzNKfpXO.cjs +7726 -0
- package/dist/create-table-card-BzNKfpXO.cjs.map +1 -0
- package/dist/create-table-card-pZ0Aq6rr.js +7685 -0
- package/dist/create-table-card-pZ0Aq6rr.js.map +1 -0
- package/dist/delete-confirm-dialog-Ch4tWj6B.cjs +42 -0
- package/dist/delete-confirm-dialog-Ch4tWj6B.cjs.map +1 -0
- package/dist/delete-confirm-dialog-K0AWE643.js +37 -0
- package/dist/delete-confirm-dialog-K0AWE643.js.map +1 -0
- package/dist/empty-state-card-DMn8ADRq.cjs +62 -0
- package/dist/empty-state-card-DMn8ADRq.cjs.map +1 -0
- package/dist/empty-state-card-Dnn36JVH.js +57 -0
- package/dist/empty-state-card-Dnn36JVH.js.map +1 -0
- package/dist/fields.cjs +8 -7763
- package/dist/fields.d.cts +39 -39
- package/dist/fields.d.ts +39 -39
- package/dist/fields.js +2 -7735
- package/dist/generated-types-DZMUyNBH.d.cts +27 -0
- package/dist/generated-types-DZMUyNBH.d.ts +27 -0
- package/dist/index-9h0EROdb.d.cts +56 -0
- package/dist/index-CwQ9QpxA.d.ts +7 -0
- package/dist/index-DOWB1UBK.d.cts +56 -0
- package/dist/index-DOWB1UBK.d.ts +56 -0
- package/dist/index-Dgb_e3AP.d.cts +7 -0
- package/dist/index-p_NegPQ5.d.ts +56 -0
- package/dist/index.cjs +736 -13712
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -10
- package/dist/index.d.ts +4 -10
- package/dist/index.js +725 -13680
- package/dist/index.js.map +1 -1
- package/dist/indexes-view-CJ1WQKdp.js +736 -0
- package/dist/indexes-view-CJ1WQKdp.js.map +1 -0
- package/dist/indexes-view-peIv6QUZ.cjs +759 -0
- package/dist/indexes-view-peIv6QUZ.cjs.map +1 -0
- package/dist/indexes.cjs +6 -1041
- package/dist/indexes.d.cts +27 -27
- package/dist/indexes.d.ts +27 -27
- package/dist/indexes.js +2 -1016
- package/dist/invalidate-database-entities-9DsT5NlP.cjs +2862 -0
- package/dist/invalidate-database-entities-9DsT5NlP.cjs.map +1 -0
- package/dist/invalidate-database-entities-CmmOT3S0.js +2559 -0
- package/dist/invalidate-database-entities-CmmOT3S0.js.map +1 -0
- package/dist/keyboard-activation-BQiV0scm.js +13 -0
- package/dist/keyboard-activation-BQiV0scm.js.map +1 -0
- package/dist/keyboard-activation-D-L0IU6Y.cjs +19 -0
- package/dist/keyboard-activation-D-L0IU6Y.cjs.map +1 -0
- package/dist/policies-view-BRbpbyB6.js +1018 -0
- package/dist/policies-view-BRbpbyB6.js.map +1 -0
- package/dist/policies-view-H1HTjpmv.cjs +1023 -0
- package/dist/policies-view-H1HTjpmv.cjs.map +1 -0
- package/dist/policies.cjs +10 -5939
- package/dist/policies.d.cts +55 -50
- package/dist/policies.d.ts +55 -50
- package/dist/policies.js +4 -5911
- package/dist/policy-config-form-BwyK7DGV.js +2502 -0
- package/dist/policy-config-form-BwyK7DGV.js.map +1 -0
- package/dist/policy-config-form-CefFo6Fw.cjs +2629 -0
- package/dist/policy-config-form-CefFo6Fw.cjs.map +1 -0
- package/dist/policy-types-D_sYWb-b.d.cts +81 -0
- package/dist/policy-types-D_sYWb-b.d.ts +81 -0
- package/dist/query-BmN_qO0W.js +171 -0
- package/dist/query-BmN_qO0W.js.map +1 -0
- package/dist/query-DU-KZleN.cjs +212 -0
- package/dist/query-DU-KZleN.cjs.map +1 -0
- package/dist/relationships-view-B5TAcPHU.cjs +2452 -0
- package/dist/relationships-view-B5TAcPHU.cjs.map +1 -0
- package/dist/relationships-view-DbwFh5r-.js +2417 -0
- package/dist/relationships-view-DbwFh5r-.js.map +1 -0
- package/dist/relationships.cjs +9 -4328
- package/dist/relationships.d.cts +93 -92
- package/dist/relationships.d.ts +93 -92
- package/dist/relationships.js +2 -4300
- package/dist/rolldown-runtime-D_qnwXdH.cjs +35 -0
- package/dist/schema-builder-sidebar-Ctu621Vw.cjs +604 -0
- package/dist/schema-builder-sidebar-Ctu621Vw.cjs.map +1 -0
- package/dist/schema-builder-sidebar-VR-Ctidc.js +593 -0
- package/dist/schema-builder-sidebar-VR-Ctidc.js.map +1 -0
- package/dist/table-editor-C-hHz3DJ.cjs +1935 -0
- package/dist/table-editor-C-hHz3DJ.cjs.map +1 -0
- package/dist/table-editor-IVp3B4nG.js +1906 -0
- package/dist/table-editor-IVp3B4nG.js.map +1 -0
- package/dist/tables.cjs +6 -5643
- package/dist/tables.d.cts +22 -21
- package/dist/tables.d.ts +22 -21
- package/dist/tables.js +3 -5618
- package/dist/testing.cjs +63 -62
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +4 -4
- package/dist/testing.d.ts +4 -4
- package/dist/testing.js +62 -61
- package/dist/testing.js.map +1 -1
- package/dist/types-GUrH1Qny.d.cts +200 -0
- package/dist/types-GUrH1Qny.d.ts +200 -0
- package/dist/use-update-table-C7v3gRyG.cjs +291 -0
- package/dist/use-update-table-C7v3gRyG.cjs.map +1 -0
- package/dist/use-update-table-Dz6knGoH.js +244 -0
- package/dist/use-update-table-Dz6knGoH.js.map +1 -0
- package/package.json +6 -6
- package/dist/core.cjs.map +0 -1
- package/dist/core.js.map +0 -1
- package/dist/fields.cjs.map +0 -1
- package/dist/fields.js.map +0 -1
- package/dist/generated-types-CnAlqHU_.d.cts +0 -25
- package/dist/generated-types-CnAlqHU_.d.ts +0 -25
- package/dist/indexes.cjs.map +0 -1
- package/dist/indexes.js.map +0 -1
- package/dist/policies.cjs.map +0 -1
- package/dist/policies.js.map +0 -1
- package/dist/policy-types-CEYAR5TN.d.cts +0 -79
- package/dist/policy-types-CEYAR5TN.d.ts +0 -79
- package/dist/relationships.cjs.map +0 -1
- package/dist/relationships.js.map +0 -1
- package/dist/tables.cjs.map +0 -1
- package/dist/tables.js.map +0 -1
- package/dist/types-Du86atZ8.d.cts +0 -199
- package/dist/types-Du86atZ8.d.ts +0 -199
- package/dist/types-bX2dCrdl.d.cts +0 -52
- package/dist/types-bX2dCrdl.d.ts +0 -52
|
@@ -0,0 +1,1023 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
const require_invalidate_database_entities = require('./invalidate-database-entities-9DsT5NlP.cjs');
|
|
3
|
+
const require_policy_config_form = require('./policy-config-form-CefFo6Fw.cjs');
|
|
4
|
+
const require_card_widths = require('./card-widths-CmIxkRfh.cjs');
|
|
5
|
+
const require_empty_state_card = require('./empty-state-card-DMn8ADRq.cjs');
|
|
6
|
+
const require_create_table_card = require('./create-table-card-BzNKfpXO.cjs');
|
|
7
|
+
let _constructive_io_ui_stack = require("@constructive-io/ui/stack");
|
|
8
|
+
let react = require("react");
|
|
9
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
10
|
+
let lucide_react = require("lucide-react");
|
|
11
|
+
let _tanstack_react_query = require("@tanstack/react-query");
|
|
12
|
+
let _constructive_io_ui_button = require("@constructive-io/ui/button");
|
|
13
|
+
let _constructive_io_ui_toast = require("@constructive-io/ui/toast");
|
|
14
|
+
let _constructive_io_ui_scroll_area = require("@constructive-io/ui/scroll-area");
|
|
15
|
+
let _constructive_io_ui_responsive_diagram = require("@constructive-io/ui/responsive-diagram");
|
|
16
|
+
let _constructive_io_ui_switch = require("@constructive-io/ui/switch");
|
|
17
|
+
let _constructive_io_ui_collapsible = require("@constructive-io/ui/collapsible");
|
|
18
|
+
|
|
19
|
+
//#region src/schema/schema-builder-core/components/policies/policy-diagram/diagram-themes.ts
|
|
20
|
+
const AMBIENT_LIGHT = {
|
|
21
|
+
bg: "#ffffff",
|
|
22
|
+
text: "#4B5563",
|
|
23
|
+
muted: "#9CA3AF"
|
|
24
|
+
};
|
|
25
|
+
const AMBIENT_DARK = {
|
|
26
|
+
bg: "#1e293b",
|
|
27
|
+
text: "#D1D5DB",
|
|
28
|
+
muted: "#6B7280"
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Full theme definitions for each policy type (light + dark).
|
|
32
|
+
*/
|
|
33
|
+
const DIAGRAM_THEMES = {
|
|
34
|
+
AuthzDirectOwner: {
|
|
35
|
+
light: {
|
|
36
|
+
primary: "#22C55E",
|
|
37
|
+
fill: "#DCFCE7",
|
|
38
|
+
border: "#86EFAC",
|
|
39
|
+
connector: "#22C55E",
|
|
40
|
+
connectorLight: "#BBF7D0",
|
|
41
|
+
...AMBIENT_LIGHT
|
|
42
|
+
},
|
|
43
|
+
dark: {
|
|
44
|
+
primary: "#4ADE80",
|
|
45
|
+
fill: "#052E16",
|
|
46
|
+
border: "#166534",
|
|
47
|
+
connector: "#4ADE80",
|
|
48
|
+
connectorLight: "#15803D",
|
|
49
|
+
...AMBIENT_DARK
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
AuthzDirectOwnerAny: {
|
|
53
|
+
light: {
|
|
54
|
+
primary: "#F97316",
|
|
55
|
+
fill: "#FFEDD5",
|
|
56
|
+
border: "#FDBA74",
|
|
57
|
+
connector: "#F97316",
|
|
58
|
+
connectorLight: "#FED7AA",
|
|
59
|
+
...AMBIENT_LIGHT
|
|
60
|
+
},
|
|
61
|
+
dark: {
|
|
62
|
+
primary: "#FB923C",
|
|
63
|
+
fill: "#431407",
|
|
64
|
+
border: "#9A3412",
|
|
65
|
+
connector: "#FB923C",
|
|
66
|
+
connectorLight: "#C2410C",
|
|
67
|
+
...AMBIENT_DARK
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
AuthzEntityMembership: {
|
|
71
|
+
light: {
|
|
72
|
+
primary: "#6366F1",
|
|
73
|
+
fill: "#E0E7FF",
|
|
74
|
+
border: "#A5B4FC",
|
|
75
|
+
connector: "#6366F1",
|
|
76
|
+
connectorLight: "#C7D2FE",
|
|
77
|
+
...AMBIENT_LIGHT
|
|
78
|
+
},
|
|
79
|
+
dark: {
|
|
80
|
+
primary: "#818CF8",
|
|
81
|
+
fill: "#1E1B4B",
|
|
82
|
+
border: "#3730A3",
|
|
83
|
+
connector: "#818CF8",
|
|
84
|
+
connectorLight: "#4F46E5",
|
|
85
|
+
...AMBIENT_DARK
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
AuthzAppMembership: {
|
|
89
|
+
light: {
|
|
90
|
+
primary: "#14B8A6",
|
|
91
|
+
fill: "#CCFBF1",
|
|
92
|
+
border: "#5EEAD4",
|
|
93
|
+
connector: "#14B8A6",
|
|
94
|
+
connectorLight: "#99F6E4",
|
|
95
|
+
...AMBIENT_LIGHT
|
|
96
|
+
},
|
|
97
|
+
dark: {
|
|
98
|
+
primary: "#2DD4BF",
|
|
99
|
+
fill: "#042F2E",
|
|
100
|
+
border: "#115E59",
|
|
101
|
+
connector: "#2DD4BF",
|
|
102
|
+
connectorLight: "#0D9488",
|
|
103
|
+
...AMBIENT_DARK
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
AuthzRelatedMemberList: {
|
|
107
|
+
light: {
|
|
108
|
+
primary: "#3B82F6",
|
|
109
|
+
fill: "#DBEAFE",
|
|
110
|
+
border: "#93C5FD",
|
|
111
|
+
connector: "#3B82F6",
|
|
112
|
+
connectorLight: "#BFDBFE",
|
|
113
|
+
...AMBIENT_LIGHT
|
|
114
|
+
},
|
|
115
|
+
dark: {
|
|
116
|
+
primary: "#60A5FA",
|
|
117
|
+
fill: "#172554",
|
|
118
|
+
border: "#1E40AF",
|
|
119
|
+
connector: "#60A5FA",
|
|
120
|
+
connectorLight: "#2563EB",
|
|
121
|
+
...AMBIENT_DARK
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
AuthzRelatedEntityMembership: {
|
|
125
|
+
light: {
|
|
126
|
+
primary: "#8B5CF6",
|
|
127
|
+
fill: "#EDE9FE",
|
|
128
|
+
border: "#C4B5FD",
|
|
129
|
+
connector: "#8B5CF6",
|
|
130
|
+
connectorLight: "#DDD6FE",
|
|
131
|
+
...AMBIENT_LIGHT
|
|
132
|
+
},
|
|
133
|
+
dark: {
|
|
134
|
+
primary: "#A78BFA",
|
|
135
|
+
fill: "#2E1065",
|
|
136
|
+
border: "#5B21B6",
|
|
137
|
+
connector: "#A78BFA",
|
|
138
|
+
connectorLight: "#7C3AED",
|
|
139
|
+
...AMBIENT_DARK
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
AuthzAllowAll: {
|
|
143
|
+
light: {
|
|
144
|
+
primary: "#10B981",
|
|
145
|
+
fill: "#D1FAE5",
|
|
146
|
+
border: "#6EE7B7",
|
|
147
|
+
connector: "#10B981",
|
|
148
|
+
connectorLight: "#A7F3D0",
|
|
149
|
+
...AMBIENT_LIGHT
|
|
150
|
+
},
|
|
151
|
+
dark: {
|
|
152
|
+
primary: "#34D399",
|
|
153
|
+
fill: "#022C22",
|
|
154
|
+
border: "#065F46",
|
|
155
|
+
connector: "#34D399",
|
|
156
|
+
connectorLight: "#047857",
|
|
157
|
+
...AMBIENT_DARK
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
AuthzDenyAll: {
|
|
161
|
+
light: {
|
|
162
|
+
primary: "#EF4444",
|
|
163
|
+
fill: "#FEE2E2",
|
|
164
|
+
border: "#FCA5A5",
|
|
165
|
+
connector: "#EF4444",
|
|
166
|
+
connectorLight: "#FECACA",
|
|
167
|
+
...AMBIENT_LIGHT
|
|
168
|
+
},
|
|
169
|
+
dark: {
|
|
170
|
+
primary: "#F87171",
|
|
171
|
+
fill: "#450A0A",
|
|
172
|
+
border: "#991B1B",
|
|
173
|
+
connector: "#F87171",
|
|
174
|
+
connectorLight: "#B91C1C",
|
|
175
|
+
...AMBIENT_DARK
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
AuthzPublishable: {
|
|
179
|
+
light: {
|
|
180
|
+
primary: "#8B5CF6",
|
|
181
|
+
fill: "#EDE9FE",
|
|
182
|
+
border: "#C4B5FD",
|
|
183
|
+
connector: "#8B5CF6",
|
|
184
|
+
connectorLight: "#DDD6FE",
|
|
185
|
+
...AMBIENT_LIGHT
|
|
186
|
+
},
|
|
187
|
+
dark: {
|
|
188
|
+
primary: "#A78BFA",
|
|
189
|
+
fill: "#2E1065",
|
|
190
|
+
border: "#5B21B6",
|
|
191
|
+
connector: "#A78BFA",
|
|
192
|
+
connectorLight: "#7C3AED",
|
|
193
|
+
...AMBIENT_DARK
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
AuthzMemberList: {
|
|
197
|
+
light: {
|
|
198
|
+
primary: "#0EA5E9",
|
|
199
|
+
fill: "#E0F2FE",
|
|
200
|
+
border: "#7DD3FC",
|
|
201
|
+
connector: "#0EA5E9",
|
|
202
|
+
connectorLight: "#BAE6FD",
|
|
203
|
+
...AMBIENT_LIGHT
|
|
204
|
+
},
|
|
205
|
+
dark: {
|
|
206
|
+
primary: "#38BDF8",
|
|
207
|
+
fill: "#082F49",
|
|
208
|
+
border: "#075985",
|
|
209
|
+
connector: "#38BDF8",
|
|
210
|
+
connectorLight: "#0369A1",
|
|
211
|
+
...AMBIENT_DARK
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
AuthzOrgHierarchy: {
|
|
215
|
+
light: {
|
|
216
|
+
primary: "#F59E0B",
|
|
217
|
+
fill: "#FEF3C7",
|
|
218
|
+
border: "#FCD34D",
|
|
219
|
+
connector: "#F59E0B",
|
|
220
|
+
connectorLight: "#FDE68A",
|
|
221
|
+
...AMBIENT_LIGHT
|
|
222
|
+
},
|
|
223
|
+
dark: {
|
|
224
|
+
primary: "#FBBF24",
|
|
225
|
+
fill: "#451A03",
|
|
226
|
+
border: "#92400E",
|
|
227
|
+
connector: "#FBBF24",
|
|
228
|
+
connectorLight: "#B45309",
|
|
229
|
+
...AMBIENT_DARK
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
AuthzTemporal: {
|
|
233
|
+
light: {
|
|
234
|
+
primary: "#EC4899",
|
|
235
|
+
fill: "#FCE7F3",
|
|
236
|
+
border: "#F9A8D4",
|
|
237
|
+
connector: "#EC4899",
|
|
238
|
+
connectorLight: "#FBCFE8",
|
|
239
|
+
...AMBIENT_LIGHT
|
|
240
|
+
},
|
|
241
|
+
dark: {
|
|
242
|
+
primary: "#F472B6",
|
|
243
|
+
fill: "#500724",
|
|
244
|
+
border: "#9D174D",
|
|
245
|
+
connector: "#F472B6",
|
|
246
|
+
connectorLight: "#BE185D",
|
|
247
|
+
...AMBIENT_DARK
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
AuthzComposite: {
|
|
251
|
+
light: {
|
|
252
|
+
primary: "#7C3AED",
|
|
253
|
+
fill: "#EDE9FE",
|
|
254
|
+
border: "#A78BFA",
|
|
255
|
+
connector: "#7C3AED",
|
|
256
|
+
connectorLight: "#DDD6FE",
|
|
257
|
+
...AMBIENT_LIGHT
|
|
258
|
+
},
|
|
259
|
+
dark: {
|
|
260
|
+
primary: "#A78BFA",
|
|
261
|
+
fill: "#2E1065",
|
|
262
|
+
border: "#5B21B6",
|
|
263
|
+
connector: "#A78BFA",
|
|
264
|
+
connectorLight: "#7C3AED",
|
|
265
|
+
...AMBIENT_DARK
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
/**
|
|
270
|
+
* Get resolved theme for a policy type in a given mode.
|
|
271
|
+
*/
|
|
272
|
+
function getDiagramTheme(key, mode = "light") {
|
|
273
|
+
return DIAGRAM_THEMES[key]?.[mode] ?? DIAGRAM_THEMES.AuthzAllowAll[mode];
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
//#endregion
|
|
277
|
+
//#region src/schema/schema-builder-core/lib/policies/rls-parser.ts
|
|
278
|
+
var IdGenerator = class {
|
|
279
|
+
counter = 1;
|
|
280
|
+
next() {
|
|
281
|
+
return `c-${this.counter++}`;
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
var MembershipByFieldParser = class {
|
|
285
|
+
canParse(tag) {
|
|
286
|
+
return tag === "AuthzEntityMembership";
|
|
287
|
+
}
|
|
288
|
+
parse(node, tag, idGen) {
|
|
289
|
+
const data = node[tag];
|
|
290
|
+
const policyTypeId = require_create_table_card.fromBackendPolicyTypeId("AuthzEntityMembership", data) ?? "OwnedRecords";
|
|
291
|
+
return {
|
|
292
|
+
id: idGen.next(),
|
|
293
|
+
type: "condition",
|
|
294
|
+
data: {
|
|
295
|
+
policyType: policyTypeId,
|
|
296
|
+
data: { ...data }
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
var RlsNodeParser = class {
|
|
302
|
+
canParse(tag) {
|
|
303
|
+
return tag in require_create_table_card.AST_NODE_TO_POLICY_TYPE;
|
|
304
|
+
}
|
|
305
|
+
parse(node, tag, idGen) {
|
|
306
|
+
const policyTypeId = require_create_table_card.AST_NODE_TO_POLICY_TYPE[tag];
|
|
307
|
+
const data = node[tag];
|
|
308
|
+
return {
|
|
309
|
+
id: idGen.next(),
|
|
310
|
+
type: "condition",
|
|
311
|
+
data: {
|
|
312
|
+
policyType: policyTypeId,
|
|
313
|
+
data: { ...data }
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
var BoolExprParser = class {
|
|
319
|
+
transformer;
|
|
320
|
+
constructor(transformer) {
|
|
321
|
+
this.transformer = transformer;
|
|
322
|
+
}
|
|
323
|
+
canParse(tag) {
|
|
324
|
+
return tag === "BoolExpr";
|
|
325
|
+
}
|
|
326
|
+
parse(node, _tag, idGen) {
|
|
327
|
+
const data = node["BoolExpr"];
|
|
328
|
+
const operator = data.boolop === "AND_EXPR" ? "AND" : "OR";
|
|
329
|
+
const args = data.args || [];
|
|
330
|
+
const children = [];
|
|
331
|
+
for (const arg of args) {
|
|
332
|
+
const child = this.transformer.transformNode(arg, idGen);
|
|
333
|
+
if (child) children.push(child);
|
|
334
|
+
}
|
|
335
|
+
if (children.length === 0) return null;
|
|
336
|
+
if (children.length === 1) return children[0];
|
|
337
|
+
return {
|
|
338
|
+
id: idGen.next(),
|
|
339
|
+
type: "group",
|
|
340
|
+
operator,
|
|
341
|
+
children
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
var AstToConditionTransformer = class {
|
|
346
|
+
parsers;
|
|
347
|
+
constructor() {
|
|
348
|
+
this.parsers = [
|
|
349
|
+
new MembershipByFieldParser(),
|
|
350
|
+
new RlsNodeParser(),
|
|
351
|
+
new BoolExprParser(this)
|
|
352
|
+
];
|
|
353
|
+
}
|
|
354
|
+
getNodeTag(node) {
|
|
355
|
+
const keys = Object.keys(node);
|
|
356
|
+
if (keys.length === 1 && /^[A-Z]/.test(keys[0])) return keys[0];
|
|
357
|
+
return null;
|
|
358
|
+
}
|
|
359
|
+
transformNode(node, idGen) {
|
|
360
|
+
const tag = this.getNodeTag(node);
|
|
361
|
+
if (!tag) return null;
|
|
362
|
+
for (const parser of this.parsers) if (parser.canParse(tag)) return parser.parse(node, tag, idGen);
|
|
363
|
+
return null;
|
|
364
|
+
}
|
|
365
|
+
transform(ast) {
|
|
366
|
+
const idGen = new IdGenerator();
|
|
367
|
+
const result = this.transformNode(ast, idGen);
|
|
368
|
+
if (!result) return {
|
|
369
|
+
id: "root",
|
|
370
|
+
type: "group",
|
|
371
|
+
operator: "AND",
|
|
372
|
+
children: []
|
|
373
|
+
};
|
|
374
|
+
if (result.type === "group") return {
|
|
375
|
+
...result,
|
|
376
|
+
id: "root"
|
|
377
|
+
};
|
|
378
|
+
return {
|
|
379
|
+
id: "root",
|
|
380
|
+
type: "group",
|
|
381
|
+
operator: "AND",
|
|
382
|
+
children: [result]
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
const transformer = new AstToConditionTransformer();
|
|
387
|
+
function mapAstToConditionNode(ast) {
|
|
388
|
+
return transformer.transform(ast);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
//#endregion
|
|
392
|
+
//#region src/schema/schema-builder-policies/components/table-editor/policies/use-policy-edit-state.ts
|
|
393
|
+
function getInitialState(policy) {
|
|
394
|
+
return {
|
|
395
|
+
roleName: policy.granteeName ?? "authenticated",
|
|
396
|
+
isPermissive: policy.permissive ?? true,
|
|
397
|
+
isEnabled: !(policy.disabled ?? false),
|
|
398
|
+
policyData: policy.data ?? {}
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Hook for managing policy edit form state and change detection
|
|
403
|
+
*/
|
|
404
|
+
function usePolicyEditState(policy) {
|
|
405
|
+
const [state, setState] = (0, react.useState)(() => getInitialState(policy));
|
|
406
|
+
const updateState = (0, react.useCallback)((updates) => {
|
|
407
|
+
setState((prev) => ({
|
|
408
|
+
...prev,
|
|
409
|
+
...updates
|
|
410
|
+
}));
|
|
411
|
+
}, []);
|
|
412
|
+
const updatePolicyData = (0, react.useCallback)((updates) => {
|
|
413
|
+
setState((prev) => ({
|
|
414
|
+
...prev,
|
|
415
|
+
policyData: {
|
|
416
|
+
...prev.policyData,
|
|
417
|
+
...updates
|
|
418
|
+
}
|
|
419
|
+
}));
|
|
420
|
+
}, []);
|
|
421
|
+
const reset = (0, react.useCallback)(() => {
|
|
422
|
+
setState(getInitialState(policy));
|
|
423
|
+
}, [policy]);
|
|
424
|
+
return {
|
|
425
|
+
state,
|
|
426
|
+
updateState,
|
|
427
|
+
updatePolicyData,
|
|
428
|
+
hasChanges: (0, react.useMemo)(() => {
|
|
429
|
+
const original = getInitialState(policy);
|
|
430
|
+
return state.roleName !== original.roleName || state.isPermissive !== original.isPermissive || state.isEnabled !== original.isEnabled || JSON.stringify(state.policyData) !== JSON.stringify(original.policyData);
|
|
431
|
+
}, [policy, state]),
|
|
432
|
+
reset
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
//#endregion
|
|
437
|
+
//#region src/schema/schema-builder-policies/components/table-editor/policies/policy-edit-card.tsx
|
|
438
|
+
const PRIVILEGE_CONFIG = {
|
|
439
|
+
SELECT: {
|
|
440
|
+
label: "Read",
|
|
441
|
+
bg: "bg-sky-500/10",
|
|
442
|
+
text: "text-sky-600 dark:text-sky-400",
|
|
443
|
+
icon: lucide_react.Search
|
|
444
|
+
},
|
|
445
|
+
INSERT: {
|
|
446
|
+
label: "Create",
|
|
447
|
+
bg: "bg-emerald-500/10",
|
|
448
|
+
text: "text-emerald-600 dark:text-emerald-400",
|
|
449
|
+
icon: lucide_react.Plus
|
|
450
|
+
},
|
|
451
|
+
UPDATE: {
|
|
452
|
+
label: "Update",
|
|
453
|
+
bg: "bg-amber-500/10",
|
|
454
|
+
text: "text-amber-600 dark:text-amber-400",
|
|
455
|
+
icon: lucide_react.Pencil
|
|
456
|
+
},
|
|
457
|
+
DELETE: {
|
|
458
|
+
label: "Delete",
|
|
459
|
+
bg: "bg-rose-500/10",
|
|
460
|
+
text: "text-rose-600 dark:text-rose-400",
|
|
461
|
+
icon: lucide_react.Trash2
|
|
462
|
+
}
|
|
463
|
+
};
|
|
464
|
+
/**
|
|
465
|
+
* Card component for editing an existing policy.
|
|
466
|
+
* Shows policy header, diagram, settings form, and access rule config.
|
|
467
|
+
*/
|
|
468
|
+
const PolicyEditCard = ({ policy, tableName, onSuccess, card }) => {
|
|
469
|
+
const { currentDatabase } = require_invalidate_database_entities.useSchemaBuilderSelectors();
|
|
470
|
+
const schemaId = currentDatabase?.schemaId ?? "";
|
|
471
|
+
const { policyType, isLoading: isPolicyTypeLoading } = require_policy_config_form.usePolicyType(policy.policyType ?? "");
|
|
472
|
+
const { policyTypes } = require_policy_config_form.usePolicyTypes();
|
|
473
|
+
const updatePolicyMutation = require_invalidate_database_entities.useUpdatePolicyMutation({ selection: { fields: { id: true } } });
|
|
474
|
+
const deletePolicyMutation = require_invalidate_database_entities.useDeletePolicyMutation({ selection: { fields: { id: true } } });
|
|
475
|
+
const isCompositePolicy = policy.policyType === "AuthzComposite";
|
|
476
|
+
const { state, updateState, updatePolicyData, hasChanges } = usePolicyEditState(policy);
|
|
477
|
+
const [compositeData, setCompositeData] = (0, react.useState)((0, react.useMemo)(() => {
|
|
478
|
+
if (!isCompositePolicy || !policy.data) return null;
|
|
479
|
+
try {
|
|
480
|
+
return mapAstToConditionNode(policy.data);
|
|
481
|
+
} catch {
|
|
482
|
+
return null;
|
|
483
|
+
}
|
|
484
|
+
}, [isCompositePolicy, policy.data]));
|
|
485
|
+
const [compositeDataChanged, setCompositeDataChanged] = (0, react.useState)(false);
|
|
486
|
+
const handleCompositeChange = (data) => {
|
|
487
|
+
setCompositeData(data);
|
|
488
|
+
setCompositeDataChanged(true);
|
|
489
|
+
};
|
|
490
|
+
const handleSubmit = async () => {
|
|
491
|
+
if (!policyType || !schemaId) return;
|
|
492
|
+
try {
|
|
493
|
+
const dataToSubmit = isCompositePolicy && compositeData ? require_create_table_card.mapConditionNodeToAst(compositeData) ?? {} : require_policy_config_form.injectSchemaFields(state.policyData, schemaId, policyType.name);
|
|
494
|
+
await updatePolicyMutation.mutateAsync({
|
|
495
|
+
id: policy.id,
|
|
496
|
+
policyPatch: {
|
|
497
|
+
permissive: state.isPermissive,
|
|
498
|
+
disabled: !state.isEnabled,
|
|
499
|
+
data: dataToSubmit
|
|
500
|
+
}
|
|
501
|
+
});
|
|
502
|
+
(0, _constructive_io_ui_toast.showSuccessToast)({
|
|
503
|
+
message: "Policy updated",
|
|
504
|
+
description: `Policy "${policy.name}" has been updated successfully.`
|
|
505
|
+
});
|
|
506
|
+
onSuccess?.();
|
|
507
|
+
card.close();
|
|
508
|
+
} catch (error) {
|
|
509
|
+
(0, _constructive_io_ui_toast.showErrorToast)({
|
|
510
|
+
message: "Failed to update policy",
|
|
511
|
+
description: error instanceof Error ? error.message : "An unexpected error occurred."
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
};
|
|
515
|
+
const handleFormSubmit = (e) => {
|
|
516
|
+
e.preventDefault();
|
|
517
|
+
const canSubmit = isCompositePolicy ? compositeDataChanged || hasChanges : hasChanges;
|
|
518
|
+
if (!updatePolicyMutation.isPending && canSubmit) handleSubmit();
|
|
519
|
+
};
|
|
520
|
+
const handleDelete = async () => {
|
|
521
|
+
try {
|
|
522
|
+
await deletePolicyMutation.mutateAsync({ id: policy.id });
|
|
523
|
+
(0, _constructive_io_ui_toast.showSuccessToast)({
|
|
524
|
+
message: "Policy deleted",
|
|
525
|
+
description: `Policy "${policy.name}" has been deleted.`
|
|
526
|
+
});
|
|
527
|
+
onSuccess?.();
|
|
528
|
+
card.close();
|
|
529
|
+
} catch (error) {
|
|
530
|
+
(0, _constructive_io_ui_toast.showErrorToast)({
|
|
531
|
+
message: "Failed to delete policy",
|
|
532
|
+
description: error instanceof Error ? error.message : "An unexpected error occurred."
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
};
|
|
536
|
+
const hasAnyChanges = isCompositePolicy ? compositeDataChanged || hasChanges : hasChanges;
|
|
537
|
+
const isLoading = updatePolicyMutation.isPending || deletePolicyMutation.isPending;
|
|
538
|
+
if (isPolicyTypeLoading) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
539
|
+
className: "flex h-full items-center justify-center",
|
|
540
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Loader2Icon, { className: "text-muted-foreground h-6 w-6 animate-spin" })
|
|
541
|
+
});
|
|
542
|
+
if (!policyType) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
543
|
+
className: "flex h-full items-center justify-center p-6",
|
|
544
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
545
|
+
className: "text-muted-foreground text-sm",
|
|
546
|
+
children: "Policy type not found"
|
|
547
|
+
})
|
|
548
|
+
});
|
|
549
|
+
const PolicyIcon = policyType.icon;
|
|
550
|
+
const privilege = policy.privilege ?? "SELECT";
|
|
551
|
+
const privilegeConfig = PRIVILEGE_CONFIG[privilege] ?? PRIVILEGE_CONFIG.SELECT;
|
|
552
|
+
const PrivilegeIcon = privilegeConfig.icon;
|
|
553
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("form", {
|
|
554
|
+
onSubmit: handleFormSubmit,
|
|
555
|
+
"data-chat-component": "policy-edit-card",
|
|
556
|
+
"data-chat-policy-type": policy.policyType ?? "",
|
|
557
|
+
"data-chat-privilege": policy.privilege ?? "",
|
|
558
|
+
"data-chat-table-name": tableName,
|
|
559
|
+
"data-chat-enabled": String(state.isEnabled),
|
|
560
|
+
"data-chat-permissive": String(state.isPermissive),
|
|
561
|
+
className: "flex h-full flex-col",
|
|
562
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_scroll_area.ScrollArea, {
|
|
563
|
+
className: "min-h-0 flex-1",
|
|
564
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
565
|
+
className: "space-y-6 p-6",
|
|
566
|
+
children: [
|
|
567
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
568
|
+
className: "space-y-4",
|
|
569
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
570
|
+
className: "flex items-start gap-3",
|
|
571
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
572
|
+
className: "bg-primary/10 flex size-10 shrink-0 items-center justify-center rounded-lg",
|
|
573
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PolicyIcon, { className: "text-primary size-5" })
|
|
574
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
575
|
+
className: "min-w-0 flex-1",
|
|
576
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
577
|
+
className: "flex items-center gap-2",
|
|
578
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", {
|
|
579
|
+
className: "text-balance font-semibold",
|
|
580
|
+
children: policyType.title
|
|
581
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
582
|
+
className: `inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-xs font-medium
|
|
583
|
+
${privilegeConfig.bg} ${privilegeConfig.text}`,
|
|
584
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(PrivilegeIcon, { className: "size-3" }), privilegeConfig.label]
|
|
585
|
+
})]
|
|
586
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
587
|
+
className: "text-muted-foreground text-sm",
|
|
588
|
+
children: policyType.description
|
|
589
|
+
})]
|
|
590
|
+
})]
|
|
591
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_responsive_diagram.ResponsiveDiagram, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_create_table_card.PolicyDiagramByKey, {
|
|
592
|
+
diagramKey: policyType.diagramKey ?? "AuthzAllowAll",
|
|
593
|
+
tableName,
|
|
594
|
+
config: state.policyData
|
|
595
|
+
}) })]
|
|
596
|
+
}),
|
|
597
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
598
|
+
className: "space-y-3",
|
|
599
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
600
|
+
className: "text-muted-foreground text-xs font-semibold tracking-wide uppercase",
|
|
601
|
+
children: "Settings"
|
|
602
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
603
|
+
className: "flex items-center justify-between",
|
|
604
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
605
|
+
className: "text-sm font-medium",
|
|
606
|
+
children: "Policy Status"
|
|
607
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
608
|
+
className: "flex items-center gap-2",
|
|
609
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_switch.Switch, {
|
|
610
|
+
id: "policy-enabled",
|
|
611
|
+
checked: state.isEnabled,
|
|
612
|
+
onCheckedChange: (checked) => updateState({ isEnabled: checked }),
|
|
613
|
+
disabled: updatePolicyMutation.isPending
|
|
614
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
615
|
+
className: "text-muted-foreground w-16 text-sm",
|
|
616
|
+
children: state.isEnabled ? "Enabled" : "Disabled"
|
|
617
|
+
})]
|
|
618
|
+
})]
|
|
619
|
+
})]
|
|
620
|
+
}),
|
|
621
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
622
|
+
className: "space-y-3",
|
|
623
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
624
|
+
className: "text-muted-foreground text-xs font-semibold tracking-wide uppercase",
|
|
625
|
+
children: "Access Rule Config"
|
|
626
|
+
}), isCompositePolicy ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_create_table_card.CompositePolicyBuilder, {
|
|
627
|
+
value: compositeData,
|
|
628
|
+
onChange: handleCompositeChange,
|
|
629
|
+
policyTypes,
|
|
630
|
+
disabled: updatePolicyMutation.isPending
|
|
631
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_policy_config_form.PolicyConfigForm, {
|
|
632
|
+
policyType,
|
|
633
|
+
value: state.policyData,
|
|
634
|
+
onChange: updatePolicyData,
|
|
635
|
+
disabled: updatePolicyMutation.isPending,
|
|
636
|
+
hideAutoGeneratedInfo: true
|
|
637
|
+
})]
|
|
638
|
+
})
|
|
639
|
+
]
|
|
640
|
+
})
|
|
641
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
642
|
+
className: "flex justify-between border-t px-4 py-3",
|
|
643
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_constructive_io_ui_button.Button, {
|
|
644
|
+
type: "button",
|
|
645
|
+
variant: "ghost",
|
|
646
|
+
onClick: handleDelete,
|
|
647
|
+
disabled: isLoading,
|
|
648
|
+
className: "text-destructive hover:text-destructive hover:bg-destructive/10",
|
|
649
|
+
children: [deletePolicyMutation.isPending ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Loader2Icon, { className: "mr-1.5 size-4 animate-spin" }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Trash2, { className: "mr-1.5 size-4" }), deletePolicyMutation.isPending ? "Deleting..." : "Delete"]
|
|
650
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
651
|
+
className: "flex gap-2",
|
|
652
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_button.Button, {
|
|
653
|
+
type: "button",
|
|
654
|
+
variant: "outline",
|
|
655
|
+
onClick: () => card.close(),
|
|
656
|
+
disabled: isLoading,
|
|
657
|
+
children: "Cancel"
|
|
658
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_constructive_io_ui_button.Button, {
|
|
659
|
+
type: "submit",
|
|
660
|
+
disabled: isLoading || !hasAnyChanges,
|
|
661
|
+
children: [updatePolicyMutation.isPending && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Loader2Icon, { className: "mr-2 h-4 w-4 animate-spin" }), updatePolicyMutation.isPending ? "Saving..." : "Save"]
|
|
662
|
+
})]
|
|
663
|
+
})]
|
|
664
|
+
})]
|
|
665
|
+
});
|
|
666
|
+
};
|
|
667
|
+
|
|
668
|
+
//#endregion
|
|
669
|
+
//#region src/schema/schema-builder-policies/components/table-editor/policies/policy-pill.tsx
|
|
670
|
+
function getPolicyThemeKey$1(policyType) {
|
|
671
|
+
if (!policyType) return "AuthzAllowAll";
|
|
672
|
+
return policyType in require_policy_config_form.POLICY_TYPE_UI_CONFIG ? policyType : "AuthzAllowAll";
|
|
673
|
+
}
|
|
674
|
+
function PolicyPill({ policy, onClick }) {
|
|
675
|
+
const config = policy.policyType ? require_policy_config_form.POLICY_TYPE_UI_CONFIG[policy.policyType] : null;
|
|
676
|
+
const title = config?.fallbackTitle ?? policy.policyType ?? policy.name ?? "Policy";
|
|
677
|
+
const isDisabled = policy.disabled === true;
|
|
678
|
+
const Icon = config?.icon ?? lucide_react.Shield;
|
|
679
|
+
const { colorMode: resolvedTheme } = require_invalidate_database_entities.useSchemaBuilderRuntime();
|
|
680
|
+
const mode = resolvedTheme === "dark" ? "dark" : "light";
|
|
681
|
+
const theme = getDiagramTheme(getPolicyThemeKey$1(policy.policyType), mode);
|
|
682
|
+
const lighterBg = theme.fill + "80";
|
|
683
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
684
|
+
type: "button",
|
|
685
|
+
onClick,
|
|
686
|
+
className: require_invalidate_database_entities.cn("group inline-flex min-h-10 items-center gap-1 rounded-full px-3 py-1", "border text-xs font-semibold", `cursor-pointer transition-[scale,box-shadow] duration-150 ease-out
|
|
687
|
+
motion-safe:active:scale-[0.96]`, "hover:scale-[1.02] hover:shadow-sm", "focus-visible:ring-ring focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none", isDisabled && "opacity-60"),
|
|
688
|
+
style: {
|
|
689
|
+
backgroundColor: lighterBg,
|
|
690
|
+
borderColor: theme.border,
|
|
691
|
+
color: theme.primary
|
|
692
|
+
},
|
|
693
|
+
children: [
|
|
694
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Icon, {
|
|
695
|
+
className: "size-3 group-hover:hidden",
|
|
696
|
+
style: { color: theme.primary }
|
|
697
|
+
}),
|
|
698
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Pencil, {
|
|
699
|
+
className: "hidden size-3 group-hover:block",
|
|
700
|
+
style: { color: theme.primary }
|
|
701
|
+
}),
|
|
702
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: title })
|
|
703
|
+
]
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
//#endregion
|
|
708
|
+
//#region src/schema/schema-builder-policies/components/table-editor/policies/policy-operation-group.tsx
|
|
709
|
+
const OPERATION_ICONS = {
|
|
710
|
+
Plus: lucide_react.PlusCircle,
|
|
711
|
+
Search: lucide_react.Eye,
|
|
712
|
+
Pencil: lucide_react.Pencil,
|
|
713
|
+
Trash2: lucide_react.Trash2
|
|
714
|
+
};
|
|
715
|
+
const OPERATION_DISPLAY_NAMES = {
|
|
716
|
+
read: "Read",
|
|
717
|
+
create: "Create",
|
|
718
|
+
update: "Update",
|
|
719
|
+
delete: "Delete"
|
|
720
|
+
};
|
|
721
|
+
function getDiagramKey(policyType) {
|
|
722
|
+
if (!policyType || !(policyType in require_policy_config_form.POLICY_TYPE_UI_CONFIG)) return null;
|
|
723
|
+
return policyType;
|
|
724
|
+
}
|
|
725
|
+
function getPolicyThemeKey(policyType) {
|
|
726
|
+
if (!policyType) return "AuthzAllowAll";
|
|
727
|
+
return policyType in require_policy_config_form.POLICY_TYPE_UI_CONFIG ? policyType : "AuthzAllowAll";
|
|
728
|
+
}
|
|
729
|
+
function PolicyOperationGroup({ operation, policies, tableName, onPolicyClick, onAddClick }) {
|
|
730
|
+
const [isOpen, setIsOpen] = (0, react.useState)(false);
|
|
731
|
+
const { colorMode: resolvedTheme } = require_invalidate_database_entities.useSchemaBuilderRuntime();
|
|
732
|
+
const mode = resolvedTheme === "dark" ? "dark" : "light";
|
|
733
|
+
const style = require_policy_config_form.OPERATION_STYLES[operation];
|
|
734
|
+
const Icon = OPERATION_ICONS[style.iconName];
|
|
735
|
+
const visiblePolicies = policies.filter((p) => !require_policy_config_form.POLICY_TYPE_UI_CONFIG[p.policyType ?? ""]?.disabled);
|
|
736
|
+
const hasPolicies = visiblePolicies.length > 0;
|
|
737
|
+
(0, react.useEffect)(() => {
|
|
738
|
+
if (!hasPolicies) setIsOpen(false);
|
|
739
|
+
}, [hasPolicies]);
|
|
740
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_collapsible.Collapsible, {
|
|
741
|
+
open: isOpen,
|
|
742
|
+
onOpenChange: hasPolicies ? setIsOpen : void 0,
|
|
743
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
744
|
+
"data-chat-component": "policy-operation-group",
|
|
745
|
+
"data-chat-operation": operation,
|
|
746
|
+
"data-chat-policy-count": String(visiblePolicies.length),
|
|
747
|
+
"data-chat-policy-types": visiblePolicies.map((p) => {
|
|
748
|
+
return `${require_policy_config_form.POLICY_TYPE_UI_CONFIG[p.policyType ?? ""]?.fallbackTitle ?? p.policyType ?? "unknown"} (${p.policyType ?? "unknown"})`;
|
|
749
|
+
}).join(", "),
|
|
750
|
+
className: "border-border/60 bg-card overflow-hidden rounded-lg border",
|
|
751
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
752
|
+
className: "p-4",
|
|
753
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
754
|
+
className: "flex items-center gap-3",
|
|
755
|
+
children: [
|
|
756
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
757
|
+
className: "bg-muted/60 flex size-8 shrink-0 items-center justify-center rounded-lg",
|
|
758
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Icon, { className: "text-muted-foreground size-4" })
|
|
759
|
+
}),
|
|
760
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", {
|
|
761
|
+
className: "min-w-0 flex-1 text-balance text-sm font-semibold",
|
|
762
|
+
children: OPERATION_DISPLAY_NAMES[operation]
|
|
763
|
+
}),
|
|
764
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
765
|
+
className: "flex shrink-0 items-center gap-2",
|
|
766
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_constructive_io_ui_button.Button, {
|
|
767
|
+
variant: "outline",
|
|
768
|
+
size: "sm",
|
|
769
|
+
onClick: onAddClick,
|
|
770
|
+
className: "px-3",
|
|
771
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Plus, { className: "size-4" }), "Add Policy"]
|
|
772
|
+
}), hasPolicies ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_collapsible.CollapsibleTrigger, {
|
|
773
|
+
asChild: true,
|
|
774
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
775
|
+
type: "button",
|
|
776
|
+
"aria-label": isOpen ? "Collapse policies" : "Expand policies",
|
|
777
|
+
className: "text-muted-foreground hover:text-foreground hover:bg-muted/60 grid size-10 place-items-center rounded-lg\n transition-[background-color,color,scale] duration-150 ease-out motion-safe:active:scale-[0.96] focus-visible:outline-none",
|
|
778
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.ChevronDown, { className: require_invalidate_database_entities.cn("size-4 transition-transform duration-200", isOpen && "rotate-180") })
|
|
779
|
+
})
|
|
780
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { className: "size-8" })]
|
|
781
|
+
})
|
|
782
|
+
]
|
|
783
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
784
|
+
className: require_invalidate_database_entities.cn("mt-2 flex flex-wrap items-center gap-2 pl-11 transition-opacity duration-150", isOpen && "pointer-events-none h-0 mt-0 overflow-hidden opacity-0"),
|
|
785
|
+
children: hasPolicies ? visiblePolicies.map((policy) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PolicyPill, {
|
|
786
|
+
policy,
|
|
787
|
+
onClick: () => onPolicyClick(policy)
|
|
788
|
+
}, policy.id)) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
789
|
+
className: "text-muted-foreground text-sm italic",
|
|
790
|
+
children: "No active policies."
|
|
791
|
+
})
|
|
792
|
+
})]
|
|
793
|
+
}), hasPolicies && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_collapsible.CollapsibleContent, {
|
|
794
|
+
innerClassName: "px-4 pb-4 pt-0",
|
|
795
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
796
|
+
className: "space-y-3",
|
|
797
|
+
children: visiblePolicies.map((policy) => {
|
|
798
|
+
const diagramKey = getDiagramKey(policy.policyType);
|
|
799
|
+
const theme = getDiagramTheme(getPolicyThemeKey(policy.policyType), mode);
|
|
800
|
+
const config = require_policy_config_form.POLICY_TYPE_UI_CONFIG[policy.policyType ?? ""];
|
|
801
|
+
const title = config?.fallbackTitle ?? policy.policyType ?? policy.name ?? "Policy";
|
|
802
|
+
const PolicyIcon = config?.icon ?? lucide_react.Shield;
|
|
803
|
+
const description = config?.description;
|
|
804
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
805
|
+
className: require_invalidate_database_entities.cn("group/diagram flex w-full items-stretch rounded-lg border text-left", "transition-[border-color,box-shadow,opacity] duration-150 ease-out", "hover:shadow-sm", `focus-visible:ring-ring focus-visible:ring-2 focus-visible:ring-offset-2
|
|
806
|
+
focus-visible:outline-none`, policy.disabled === true && "opacity-60"),
|
|
807
|
+
style: { borderColor: theme.border },
|
|
808
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
809
|
+
className: "flex w-1/2 items-center justify-center rounded-l-lg p-3",
|
|
810
|
+
style: { backgroundColor: theme.fill + "30" },
|
|
811
|
+
children: diagramKey ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_create_table_card.PolicyDiagramByKey, {
|
|
812
|
+
diagramKey,
|
|
813
|
+
tableName,
|
|
814
|
+
config: policy.data ?? {}
|
|
815
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
816
|
+
className: "text-muted-foreground text-sm",
|
|
817
|
+
children: title
|
|
818
|
+
})
|
|
819
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
820
|
+
className: "flex w-1/2 flex-col justify-center gap-2 p-4 pl-6",
|
|
821
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
822
|
+
className: "flex items-center justify-between gap-2",
|
|
823
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
824
|
+
className: "flex items-center gap-2",
|
|
825
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
826
|
+
className: "flex size-7 shrink-0 items-center justify-center rounded-full",
|
|
827
|
+
style: {
|
|
828
|
+
backgroundColor: theme.fill,
|
|
829
|
+
color: theme.primary
|
|
830
|
+
},
|
|
831
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PolicyIcon, { className: "size-4" })
|
|
832
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
833
|
+
className: "text-sm font-semibold",
|
|
834
|
+
style: { color: theme.primary },
|
|
835
|
+
children: title
|
|
836
|
+
})]
|
|
837
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
838
|
+
type: "button",
|
|
839
|
+
onClick: () => onPolicyClick(policy),
|
|
840
|
+
className: "flex min-h-10 shrink-0 cursor-pointer items-center gap-1 rounded-full px-3 text-xs font-medium opacity-100\n transition-[opacity,scale] duration-150 ease-out motion-safe:active:scale-[0.96] sm:opacity-0\n pointer-coarse:opacity-100 group-hover/diagram:opacity-100 focus-visible:opacity-100",
|
|
841
|
+
style: { color: theme.primary },
|
|
842
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Pencil, { className: "size-3" }), "Edit"]
|
|
843
|
+
})]
|
|
844
|
+
}), description && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
845
|
+
className: "text-muted-foreground text-xs leading-relaxed",
|
|
846
|
+
children: description
|
|
847
|
+
})]
|
|
848
|
+
})]
|
|
849
|
+
}, policy.id);
|
|
850
|
+
})
|
|
851
|
+
})
|
|
852
|
+
})]
|
|
853
|
+
})
|
|
854
|
+
});
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
//#endregion
|
|
858
|
+
//#region src/schema/schema-builder-policies/components/table-editor/policies/policies-empty-state.tsx
|
|
859
|
+
function PoliciesEmptyState({ onCreateClick, tableName }) {
|
|
860
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_empty_state_card.EmptyStateCard, {
|
|
861
|
+
icon: lucide_react.Shield,
|
|
862
|
+
title: tableName ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: ["No policies for ", tableName] }) : "Create your first policy",
|
|
863
|
+
description: tableName ? `Add a row-level security policy to control access to ${tableName}. Policies determine who can read, create, update, or delete rows.` : "Create policies to control data access. Row-level security ensures users only see the data they are authorized to access.",
|
|
864
|
+
actionLabel: "Create Policy",
|
|
865
|
+
actionIcon: lucide_react.Shield,
|
|
866
|
+
onAction: onCreateClick,
|
|
867
|
+
features: [
|
|
868
|
+
{
|
|
869
|
+
icon: lucide_react.ShieldCheck,
|
|
870
|
+
title: "Row-Level Access",
|
|
871
|
+
description: "Control who can see each row"
|
|
872
|
+
},
|
|
873
|
+
{
|
|
874
|
+
icon: lucide_react.Lock,
|
|
875
|
+
title: "Secure by Default",
|
|
876
|
+
description: "Deny access unless explicitly allowed"
|
|
877
|
+
},
|
|
878
|
+
{
|
|
879
|
+
icon: lucide_react.Shield,
|
|
880
|
+
title: "Role-Based Rules",
|
|
881
|
+
description: "Different access for different roles"
|
|
882
|
+
}
|
|
883
|
+
]
|
|
884
|
+
});
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
//#endregion
|
|
888
|
+
//#region src/schema/schema-builder-policies/components/table-editor/policies/policies-view.tsx
|
|
889
|
+
function NoTableSelectedState() {
|
|
890
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
891
|
+
className: "flex min-h-0 flex-1 flex-col items-center justify-center p-6",
|
|
892
|
+
children: [
|
|
893
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
894
|
+
className: "bg-muted/50 mb-4 flex h-16 w-16 items-center justify-center rounded-full",
|
|
895
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Table2, { className: "text-muted-foreground h-8 w-8" })
|
|
896
|
+
}),
|
|
897
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", {
|
|
898
|
+
className: "mb-1 text-balance text-lg font-semibold",
|
|
899
|
+
children: "No table selected"
|
|
900
|
+
}),
|
|
901
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
902
|
+
className: "text-muted-foreground max-w-sm text-center text-sm",
|
|
903
|
+
children: "Select a table from the sidebar to view and manage its security policies."
|
|
904
|
+
})
|
|
905
|
+
]
|
|
906
|
+
});
|
|
907
|
+
}
|
|
908
|
+
function PoliciesView() {
|
|
909
|
+
const stack = (0, _constructive_io_ui_stack.useCardStack)();
|
|
910
|
+
const queryClient = (0, _tanstack_react_query.useQueryClient)();
|
|
911
|
+
const { currentTable, currentDatabase } = require_invalidate_database_entities.useSchemaBuilderSelectors();
|
|
912
|
+
const databaseId = currentDatabase?.databaseId ?? "";
|
|
913
|
+
const { data: tablesData = [], isLoading } = require_invalidate_database_entities.useDatabasePolicies(databaseId, { enabled: Boolean(databaseId) });
|
|
914
|
+
const currentTablePolicies = (0, react.useMemo)(() => {
|
|
915
|
+
if (!currentTable) return null;
|
|
916
|
+
return tablesData.find((t) => t.id === currentTable.id) ?? null;
|
|
917
|
+
}, [tablesData, currentTable])?.policies ?? [];
|
|
918
|
+
const groupedPolicies = (0, react.useMemo)(() => {
|
|
919
|
+
const groups = {
|
|
920
|
+
read: [],
|
|
921
|
+
create: [],
|
|
922
|
+
update: [],
|
|
923
|
+
delete: []
|
|
924
|
+
};
|
|
925
|
+
for (const policy of currentTablePolicies) {
|
|
926
|
+
const op = policy.privilege ? require_policy_config_form.PRIVILEGE_TO_OPERATION[policy.privilege] : void 0;
|
|
927
|
+
if (op && op in groups) groups[op].push(policy);
|
|
928
|
+
}
|
|
929
|
+
return groups;
|
|
930
|
+
}, [currentTablePolicies]);
|
|
931
|
+
if (!currentTable) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(NoTableSelectedState, {});
|
|
932
|
+
const hasPolicies = currentTablePolicies.length > 0;
|
|
933
|
+
const handleOpenCreate = (operation) => {
|
|
934
|
+
stack.push({
|
|
935
|
+
id: `policy-create-${currentTable.id}${operation ? `-${operation}` : ""}`,
|
|
936
|
+
title: operation ? `Add ${operation.toUpperCase()} Policy` : "Create New Policies",
|
|
937
|
+
description: `Add security policies to ${currentTable.name}`,
|
|
938
|
+
Component: require_create_table_card.CreateTableCard,
|
|
939
|
+
props: {
|
|
940
|
+
mode: "add-policies",
|
|
941
|
+
tableId: currentTable.id,
|
|
942
|
+
tableName: currentTable.name,
|
|
943
|
+
preSelectedOperation: operation,
|
|
944
|
+
onPoliciesCreated: () => {
|
|
945
|
+
if (databaseId) queryClient.invalidateQueries({ queryKey: require_invalidate_database_entities.databasePoliciesQueryKeys.byDatabase(databaseId) });
|
|
946
|
+
}
|
|
947
|
+
},
|
|
948
|
+
width: require_card_widths.CARD_WIDTHS.extraWide
|
|
949
|
+
});
|
|
950
|
+
};
|
|
951
|
+
const handleOpenEdit = (policy) => {
|
|
952
|
+
stack.push({
|
|
953
|
+
id: `policy-edit-${policy.id}`,
|
|
954
|
+
title: "Edit Policy",
|
|
955
|
+
description: "Update policy settings",
|
|
956
|
+
Component: PolicyEditCard,
|
|
957
|
+
props: {
|
|
958
|
+
policy: {
|
|
959
|
+
...policy,
|
|
960
|
+
tableId: currentTable.id
|
|
961
|
+
},
|
|
962
|
+
tableName: currentTable.name,
|
|
963
|
+
onSuccess: () => {
|
|
964
|
+
if (databaseId) queryClient.invalidateQueries({ queryKey: require_invalidate_database_entities.databasePoliciesQueryKeys.byDatabase(databaseId) });
|
|
965
|
+
}
|
|
966
|
+
},
|
|
967
|
+
width: 500
|
|
968
|
+
});
|
|
969
|
+
};
|
|
970
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
971
|
+
"data-chat-component": "policies-view",
|
|
972
|
+
"data-chat-table-name": currentTable.name,
|
|
973
|
+
"data-chat-policy-count": String(currentTablePolicies.length),
|
|
974
|
+
className: "flex min-h-0 flex-1 flex-col overflow-auto p-6",
|
|
975
|
+
children: isLoading ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
976
|
+
className: "flex items-center justify-center py-16",
|
|
977
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
978
|
+
className: "text-muted-foreground text-sm",
|
|
979
|
+
children: "Loading policies..."
|
|
980
|
+
})
|
|
981
|
+
}) : !hasPolicies ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PoliciesEmptyState, {
|
|
982
|
+
onCreateClick: () => handleOpenCreate(),
|
|
983
|
+
tableName: currentTable.name
|
|
984
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
985
|
+
className: "mx-auto w-full max-w-4xl space-y-6",
|
|
986
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
|
|
987
|
+
className: "text-balance text-xl font-semibold tracking-tight",
|
|
988
|
+
children: "Policies"
|
|
989
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
|
|
990
|
+
className: "text-muted-foreground mt-1 text-sm",
|
|
991
|
+
children: [
|
|
992
|
+
currentTablePolicies.length,
|
|
993
|
+
" polic",
|
|
994
|
+
currentTablePolicies.length !== 1 ? "ies" : "y",
|
|
995
|
+
" protecting",
|
|
996
|
+
" ",
|
|
997
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", {
|
|
998
|
+
className: "bg-muted rounded px-1.5 py-0.5 font-mono text-xs",
|
|
999
|
+
children: currentTable.name
|
|
1000
|
+
})
|
|
1001
|
+
]
|
|
1002
|
+
})] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1003
|
+
className: "space-y-3",
|
|
1004
|
+
children: require_policy_config_form.CRUD_OPERATIONS.map((op) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PolicyOperationGroup, {
|
|
1005
|
+
operation: op,
|
|
1006
|
+
policies: groupedPolicies[op],
|
|
1007
|
+
tableName: currentTable.name,
|
|
1008
|
+
onPolicyClick: handleOpenEdit,
|
|
1009
|
+
onAddClick: () => handleOpenCreate(op)
|
|
1010
|
+
}, op))
|
|
1011
|
+
})]
|
|
1012
|
+
})
|
|
1013
|
+
});
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
//#endregion
|
|
1017
|
+
Object.defineProperty(exports, 'PoliciesView', {
|
|
1018
|
+
enumerable: true,
|
|
1019
|
+
get: function () {
|
|
1020
|
+
return PoliciesView;
|
|
1021
|
+
}
|
|
1022
|
+
});
|
|
1023
|
+
//# sourceMappingURL=policies-view-H1HTjpmv.cjs.map
|