@fayz-ai/plugin-forms 0.9.0 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/{FormBuilder-7SWZQKFN.js → FormBuilder-YHJHF6HZ.js} +4 -4
- package/dist/{FormBuilder-7SWZQKFN.js.map → FormBuilder-YHJHF6HZ.js.map} +1 -1
- package/dist/{chunk-W2ZNJGQC.js → chunk-RBLXIKWB.js} +221 -8
- package/dist/chunk-RBLXIKWB.js.map +1 -0
- package/dist/components/AddDocumentDropdown.d.ts +1 -1
- package/dist/components/AddDocumentDropdown.d.ts.map +1 -1
- package/dist/components/DocumentFormDialog.d.ts.map +1 -1
- package/dist/components/DocumentSkeleton.d.ts +21 -0
- package/dist/components/DocumentSkeleton.d.ts.map +1 -0
- package/dist/components/FormRenderer.d.ts.map +1 -1
- package/dist/components/FormViewer.d.ts.map +1 -1
- package/dist/{CustomFormsContext.d.ts → context.d.ts} +1 -1
- package/dist/context.d.ts.map +1 -0
- package/dist/data/mock.d.ts.map +1 -1
- package/dist/data/supabase.d.ts.map +1 -1
- package/dist/data/types.d.ts +4 -1
- package/dist/data/types.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +174 -17
- package/dist/index.js.map +1 -1
- package/dist/lib/agent-tools.d.ts.map +1 -0
- package/dist/lib/document-types.d.ts.map +1 -0
- package/dist/lib/html-text.d.ts +21 -0
- package/dist/lib/html-text.d.ts.map +1 -0
- package/dist/lib/print.d.ts.map +1 -1
- package/dist/lib/timeline-source.d.ts +10 -0
- package/dist/lib/timeline-source.d.ts.map +1 -0
- package/dist/locales/en.d.ts.map +1 -1
- package/dist/locales/pt-BR.d.ts.map +1 -1
- package/dist/migrations/index.d.ts +1 -0
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/store.d.ts +5 -1
- package/dist/store.d.ts.map +1 -1
- package/dist/types.d.ts +13 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/views/TemplateListView.d.ts.map +1 -1
- package/package.json +5 -7
- package/dist/CustomFormsContext.d.ts.map +0 -1
- package/dist/agent-tools.d.ts.map +0 -1
- package/dist/chunk-W2ZNJGQC.js.map +0 -1
- package/dist/document-types.d.ts.map +0 -1
- package/src/CustomFormsContext.tsx +0 -28
- package/src/agent-tools.ts +0 -73
- package/src/components/AddDocumentDropdown.tsx +0 -92
- package/src/components/BuilderCanvas.tsx +0 -87
- package/src/components/BuilderField.tsx +0 -81
- package/src/components/DocumentFormDialog.tsx +0 -155
- package/src/components/DocumentList.tsx +0 -254
- package/src/components/FieldConfigDialog.tsx +0 -243
- package/src/components/FieldPalette.tsx +0 -81
- package/src/components/FormBuilder.tsx +0 -427
- package/src/components/FormRenderer.tsx +0 -256
- package/src/components/FormViewer.tsx +0 -94
- package/src/components/PersonDocumentsWidget.tsx +0 -229
- package/src/components/TemplateSelector.tsx +0 -91
- package/src/config.ts +0 -43
- package/src/data/index.ts +0 -3
- package/src/data/mock.ts +0 -193
- package/src/data/supabase.ts +0 -408
- package/src/data/tables.ts +0 -7
- package/src/data/types.ts +0 -33
- package/src/document-types.ts +0 -51
- package/src/index.ts +0 -234
- package/src/lib/person-fields.ts +0 -67
- package/src/lib/print.ts +0 -207
- package/src/lib/tenant.ts +0 -9
- package/src/locales/en.ts +0 -95
- package/src/locales/index.ts +0 -7
- package/src/locales/pt-BR.ts +0 -95
- package/src/migrations/000_plg_rename.sql +0 -21
- package/src/migrations/001_frm_base.sql +0 -174
- package/src/migrations/002_document_archetype.sql +0 -223
- package/src/migrations/003_agent_rpcs.sql +0 -174
- package/src/migrations/index.ts +0 -610
- package/src/store.ts +0 -167
- package/src/types.ts +0 -217
- package/src/views/CustomFormsSettingsTab.tsx +0 -105
- package/src/views/TemplateListView.tsx +0 -174
- /package/dist/{agent-tools.d.ts → lib/agent-tools.d.ts} +0 -0
- /package/dist/{document-types.d.ts → lib/document-types.d.ts} +0 -0
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
-- ============================================================================
|
|
2
|
-
-- plugin-forms 003: server-plane agent write RPC.
|
|
3
|
-
--
|
|
4
|
-
-- public.agent_forms_upsert_template — the assistant BUILDS or EDITS a form
|
|
5
|
-
-- template from any surface or channel (in-app FAB, WhatsApp, MCP). Same
|
|
6
|
-
-- contract as every agent_* RPC (agenda 005, financial 009):
|
|
7
|
-
-- (p_tenant_id, p_actor_user_id, p_payload jsonb) → jsonb
|
|
8
|
-
-- {ok:true, id, record:{...}} | {ok:false, denial:{...}} | {ok:false, error}
|
|
9
|
-
--
|
|
10
|
-
-- The grid layout is computed HERE (col 0, sequential rows, full-width span) so
|
|
11
|
-
-- the model only ever sends {type,label,required?,options?} — never positions.
|
|
12
|
-
--
|
|
13
|
-
-- Payload:
|
|
14
|
-
-- template_id? uuid — omit to CREATE, provide to EDIT
|
|
15
|
-
-- name? text — required on create
|
|
16
|
-
-- category? text — anamnesis|evolution|report|contract|general
|
|
17
|
-
-- description? text
|
|
18
|
-
-- fields? [{type,label,required?,placeholder?,options?[]}] — REPLACE all
|
|
19
|
-
-- append_fields? [{...}] — APPEND to existing
|
|
20
|
-
--
|
|
21
|
-
-- GRANT authenticated+service_role — NEVER anon (the broker calls with the pool
|
|
22
|
-
-- service key and injects tenant/actor; in-browser the signed-in user calls it
|
|
23
|
-
-- directly and spine RLS/actor guards bind them to their own tenant).
|
|
24
|
-
-- ============================================================================
|
|
25
|
-
|
|
26
|
-
CREATE OR REPLACE FUNCTION public.agent_forms_upsert_template(
|
|
27
|
-
p_tenant_id uuid,
|
|
28
|
-
p_actor_user_id uuid,
|
|
29
|
-
p_payload jsonb
|
|
30
|
-
) RETURNS jsonb
|
|
31
|
-
LANGUAGE plpgsql SECURITY DEFINER
|
|
32
|
-
SET search_path = public
|
|
33
|
-
AS $$
|
|
34
|
-
DECLARE
|
|
35
|
-
v_denial jsonb;
|
|
36
|
-
v_used int;
|
|
37
|
-
v_template_id uuid;
|
|
38
|
-
v_is_update boolean;
|
|
39
|
-
v_name text;
|
|
40
|
-
v_category text;
|
|
41
|
-
v_description text;
|
|
42
|
-
v_existing jsonb;
|
|
43
|
-
v_input jsonb;
|
|
44
|
-
v_merged jsonb;
|
|
45
|
-
v_fields jsonb;
|
|
46
|
-
v_schema jsonb;
|
|
47
|
-
v_final_id uuid;
|
|
48
|
-
BEGIN
|
|
49
|
-
-- ── payload ──────────────────────────────────────────────────────────────
|
|
50
|
-
BEGIN
|
|
51
|
-
v_template_id := NULLIF(p_payload->>'template_id','')::uuid;
|
|
52
|
-
EXCEPTION WHEN OTHERS THEN
|
|
53
|
-
RETURN jsonb_build_object('ok', false, 'error', 'invalid template_id');
|
|
54
|
-
END;
|
|
55
|
-
v_is_update := v_template_id IS NOT NULL;
|
|
56
|
-
v_name := btrim(p_payload->>'name');
|
|
57
|
-
v_category := lower(COALESCE(NULLIF(p_payload->>'category',''), 'general'));
|
|
58
|
-
v_description := left(p_payload->>'description', 1000);
|
|
59
|
-
IF v_category NOT IN ('anamnesis','evolution','report','contract','general') THEN
|
|
60
|
-
v_category := 'general';
|
|
61
|
-
END IF;
|
|
62
|
-
|
|
63
|
-
IF NOT v_is_update AND (v_name IS NULL OR v_name = '') THEN
|
|
64
|
-
RETURN jsonb_build_object('ok', false, 'error', 'name is required to create a form');
|
|
65
|
-
END IF;
|
|
66
|
-
|
|
67
|
-
-- ── authorization: role → plan → form_templates cap ──────────────────────
|
|
68
|
-
SELECT count(*) INTO v_used FROM plg_forms_templates
|
|
69
|
-
WHERE tenant_id = p_tenant_id AND is_deleted = false;
|
|
70
|
-
v_denial := agent_guard(p_tenant_id, p_actor_user_id, 'custom_forms',
|
|
71
|
-
CASE WHEN v_is_update THEN 'update' ELSE 'create' END,
|
|
72
|
-
'form_templates', v_used, CASE WHEN v_is_update THEN 0 ELSE 1 END);
|
|
73
|
-
IF v_denial IS NOT NULL THEN
|
|
74
|
-
RETURN jsonb_build_object('ok', false, 'denial', v_denial);
|
|
75
|
-
END IF;
|
|
76
|
-
|
|
77
|
-
-- ── current fields (for APPEND / to reject an unknown id) ────────────────
|
|
78
|
-
IF v_is_update THEN
|
|
79
|
-
SELECT COALESCE(schema->'fields','[]'::jsonb) INTO v_existing
|
|
80
|
-
FROM plg_forms_templates
|
|
81
|
-
WHERE id = v_template_id AND tenant_id = p_tenant_id AND is_deleted = false;
|
|
82
|
-
IF v_existing IS NULL THEN
|
|
83
|
-
RETURN jsonb_build_object('ok', false, 'error', 'unknown template for this tenant');
|
|
84
|
-
END IF;
|
|
85
|
-
ELSE
|
|
86
|
-
v_existing := '[]'::jsonb;
|
|
87
|
-
END IF;
|
|
88
|
-
|
|
89
|
-
-- ── normalize the incoming fields to the builder's FormFieldDef shape ────
|
|
90
|
-
-- (id, type, label, required, placeholder, col, colSpan, options) — row is
|
|
91
|
-
-- assigned last, across the merged list.
|
|
92
|
-
WITH src AS (
|
|
93
|
-
SELECT CASE
|
|
94
|
-
WHEN p_payload ? 'fields' THEN COALESCE(p_payload->'fields','[]'::jsonb)
|
|
95
|
-
WHEN p_payload ? 'append_fields' THEN COALESCE(p_payload->'append_fields','[]'::jsonb)
|
|
96
|
-
ELSE '[]'::jsonb
|
|
97
|
-
END AS arr
|
|
98
|
-
),
|
|
99
|
-
norm AS (
|
|
100
|
-
SELECT f.ord, jsonb_strip_nulls(jsonb_build_object(
|
|
101
|
-
'id', COALESCE(NULLIF(f.value->>'id',''), gen_random_uuid()::text),
|
|
102
|
-
'type', COALESCE(NULLIF(f.value->>'type',''), 'text'),
|
|
103
|
-
'label', COALESCE(NULLIF(f.value->>'label',''), 'Campo'),
|
|
104
|
-
'required', COALESCE((f.value->>'required')::boolean, false),
|
|
105
|
-
'placeholder', NULLIF(f.value->>'placeholder',''),
|
|
106
|
-
'col', 0,
|
|
107
|
-
'colSpan', 12,
|
|
108
|
-
'options', CASE
|
|
109
|
-
WHEN jsonb_typeof(f.value->'options') = 'array' AND jsonb_array_length(f.value->'options') > 0
|
|
110
|
-
THEN (SELECT jsonb_agg(jsonb_build_object(
|
|
111
|
-
'label', opt,
|
|
112
|
-
'value', lower(regexp_replace(btrim(opt), '\s+', '_', 'g'))))
|
|
113
|
-
FROM jsonb_array_elements_text(f.value->'options') opt)
|
|
114
|
-
ELSE NULL END
|
|
115
|
-
)) AS field
|
|
116
|
-
FROM src, jsonb_array_elements(src.arr) WITH ORDINALITY AS f(value, ord)
|
|
117
|
-
)
|
|
118
|
-
SELECT COALESCE(jsonb_agg(field ORDER BY ord), '[]'::jsonb) INTO v_input FROM norm;
|
|
119
|
-
|
|
120
|
-
-- REPLACE with `fields`; otherwise APPEND onto what's already there.
|
|
121
|
-
IF p_payload ? 'fields' THEN
|
|
122
|
-
v_merged := v_input;
|
|
123
|
-
ELSE
|
|
124
|
-
v_merged := v_existing || v_input;
|
|
125
|
-
END IF;
|
|
126
|
-
|
|
127
|
-
-- sequential rows across the final list
|
|
128
|
-
SELECT COALESCE(jsonb_agg(jsonb_set(e.value, '{row}', to_jsonb((e.ord - 1))) ORDER BY e.ord), '[]'::jsonb)
|
|
129
|
-
INTO v_fields
|
|
130
|
-
FROM jsonb_array_elements(v_merged) WITH ORDINALITY AS e(value, ord);
|
|
131
|
-
|
|
132
|
-
v_schema := jsonb_build_object('layout', jsonb_build_object('columns', 12), 'fields', v_fields);
|
|
133
|
-
|
|
134
|
-
-- ── write + audit ────────────────────────────────────────────────────────
|
|
135
|
-
IF v_is_update THEN
|
|
136
|
-
UPDATE plg_forms_templates SET
|
|
137
|
-
name = COALESCE(NULLIF(v_name,''), name),
|
|
138
|
-
category = v_category,
|
|
139
|
-
description = COALESCE(v_description, description),
|
|
140
|
-
schema = v_schema,
|
|
141
|
-
updated_by = p_actor_user_id,
|
|
142
|
-
updated_at = now()
|
|
143
|
-
WHERE id = v_template_id AND tenant_id = p_tenant_id AND is_deleted = false
|
|
144
|
-
RETURNING id INTO v_final_id;
|
|
145
|
-
ELSE
|
|
146
|
-
INSERT INTO plg_forms_templates (tenant_id, name, category, description, schema, created_by, updated_by)
|
|
147
|
-
VALUES (p_tenant_id, v_name, v_category, v_description, v_schema, p_actor_user_id, p_actor_user_id)
|
|
148
|
-
RETURNING id INTO v_final_id;
|
|
149
|
-
END IF;
|
|
150
|
-
|
|
151
|
-
INSERT INTO audit_logs (tenant_id, user_id, action, entity_type, entity_id, metadata)
|
|
152
|
-
VALUES (p_tenant_id, p_actor_user_id,
|
|
153
|
-
CASE WHEN v_is_update THEN 'agent.updateFormTemplate' ELSE 'agent.createFormTemplate' END,
|
|
154
|
-
'form_template', v_final_id::text,
|
|
155
|
-
jsonb_build_object('payload', p_payload));
|
|
156
|
-
|
|
157
|
-
RETURN jsonb_build_object(
|
|
158
|
-
'ok', true,
|
|
159
|
-
'id', v_final_id,
|
|
160
|
-
'record', jsonb_build_object(
|
|
161
|
-
'ref', jsonb_build_object('id', v_final_id, 'resource', 'plg_forms_templates',
|
|
162
|
-
'archetype', 'custom_forms:template'),
|
|
163
|
-
'name', COALESCE(NULLIF(v_name,''), (SELECT name FROM plg_forms_templates WHERE id = v_final_id)),
|
|
164
|
-
'category', v_category,
|
|
165
|
-
'fieldCount', jsonb_array_length(v_fields)
|
|
166
|
-
)
|
|
167
|
-
);
|
|
168
|
-
END;
|
|
169
|
-
$$;
|
|
170
|
-
|
|
171
|
-
REVOKE ALL ON FUNCTION public.agent_forms_upsert_template(uuid, uuid, jsonb) FROM public;
|
|
172
|
-
REVOKE EXECUTE ON FUNCTION public.agent_forms_upsert_template(uuid, uuid, jsonb) FROM anon;
|
|
173
|
-
GRANT EXECUTE ON FUNCTION public.agent_forms_upsert_template(uuid, uuid, jsonb)
|
|
174
|
-
TO authenticated, service_role;
|