@fayz-ai/plugin-tables 0.14.4 → 0.14.5
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.
|
@@ -35,6 +35,7 @@ export declare const MIGRATION_035_O_SALAO_AVISA_OS_OUTROS_TABLETS = "-- -------
|
|
|
35
35
|
export declare const MIGRATION_036_A_RLS_QUE_EXISTE_PASSA_A_SER_LEGIVEL = "-- ---------------------------------------------------------------------------\n-- 036_a_rls_que_existe_passa_a_ser_legivel.sql\n--\n-- \u2500\u2500 o que o port\u00E3o viu, e o que o banco diz \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n--\n-- `check-plugin-review` reprovou NOVE tabelas deste plugin com a frase mais\n-- s\u00E9ria que ele tem: *\u00ABcria public.X com tenant_id e nunca liga row security \u2014\n-- num cluster compartilhado isso \u00E9 cada conta lendo as linhas da outra\u00BB*.\n--\n-- Fui ao banco antes de escrever qualquer linha. **As nove t\u00EAm RLS ligada, com\n-- quatro pol\u00EDticas cada** \u2014 medido no cluster do Pertinho:\n--\n-- plg_tables_service_areas .............. rls=t, 4 pol\u00EDticas\n-- plg_tables_service_area_tables ........ rls=t, 4\n-- plg_tables_service_area_staff ......... rls=t, 4\n-- plg_tables_service_charge_snapshots ... rls=t, 4\n-- plg_tables_service_charge_waivers ..... rls=t, 4\n-- plg_tables_service_charge_audit ....... rls=t, 4\n-- plg_tables_courtesy_events ............ rls=t, 4\n-- plg_tables_order_cover_charges ........ rls=t, 4\n-- plg_tables_print_settings ............. rls=t, 4\n--\n-- N\u00E3o h\u00E1 vazamento. O que h\u00E1 \u00E9 uma garantia que o revisor N\u00C3O CONSEGUE LER: o\n-- `ENABLE` dessas tabelas mora dentro de um `DO $$ \u2026 EXECUTE format(...)`, e o\n-- port\u00E3o l\u00EA o ARQUIVO, n\u00E3o o banco.\n--\n-- A 006 deste mesmo plugin j\u00E1 tinha aprendido isso e escreveu a raz\u00E3o:\n--\n-- -- RLS, uma a uma e por extenso. O la\u00E7o adiante j\u00E1 liga tudo isto \u2014 mas ele\n-- -- liga por `EXECUTE format(...)`, e o port\u00E3o que revisa plugin l\u00EA o\n-- -- ARQUIVO: para ele, tabela com tenant_id e sem um ENABLE literal \u00E9 tabela\n-- -- aberta. Uma garantia que o revisor n\u00E3o consegue ler \u00E9 uma garantia que\n-- -- ningu\u00E9m confere.\n--\n-- As migrations que criam essas nove (014, 019, 024) **j\u00E1 foram aplicadas**, e\n-- reescrev\u00EA-las trocaria o checksum \u2014 a deriva de ledger pela qual este\n-- reposit\u00F3rio para o mundo. Ent\u00E3o a legibilidade entra por arquivo NOVO: o\n-- port\u00E3o pergunta ao SQL INTEIRO do plugin, n\u00E3o a um arquivo s\u00F3.\n--\n-- Ligar RLS j\u00E1 ligada \u00E9 no-op. Este arquivo n\u00E3o muda comportamento nenhum: ele\n-- torna confer\u00EDvel o que j\u00E1 era verdade.\n--\n-- Idempotente e replay-safe.\n-- ---------------------------------------------------------------------------\n\nALTER TABLE public.plg_tables_service_areas ENABLE ROW LEVEL SECURITY;\nALTER TABLE public.plg_tables_service_area_tables ENABLE ROW LEVEL SECURITY;\nALTER TABLE public.plg_tables_service_area_staff ENABLE ROW LEVEL SECURITY;\nALTER TABLE public.plg_tables_service_charge_snapshots ENABLE ROW LEVEL SECURITY;\nALTER TABLE public.plg_tables_service_charge_waivers ENABLE ROW LEVEL SECURITY;\nALTER TABLE public.plg_tables_service_charge_audit ENABLE ROW LEVEL SECURITY;\nALTER TABLE public.plg_tables_courtesy_events ENABLE ROW LEVEL SECURITY;\nALTER TABLE public.plg_tables_order_cover_charges ENABLE ROW LEVEL SECURITY;\nALTER TABLE public.plg_tables_print_settings ENABLE ROW LEVEL SECURITY;\n";
|
|
36
36
|
export declare const MIGRATION_037_SO_O_DONO_DO_PIN_OU_O_GERENTE_TROCA_O_PIN = "-- 016 left `comanda_set_authorizer_pin` callable by any member of the tenant:\n-- SECURITY DEFINER skips the `tables.manage` write policy, so anyone could\n-- reset another authorizer's PIN and then approve their own discount/cancel.\n-- Now: the authorizer sets their own PIN (V1 \"Meu Perfil\"), or a holder of\n-- `tables.manage` on that unit sets it for them.\n--\n-- Idempotent: create or replace.\n\ncreate or replace function public.comanda_set_authorizer_pin(\n p_authorizer_id uuid,\n p_pin text\n) returns void\n language plpgsql\n security definer\n set search_path to ''\nas $$\ndeclare\n v_tenant uuid := (select app.current_tenant_id());\n v_auth public.plg_tables_authorizers%rowtype;\n v_hash text;\nbegin\n if p_pin !~ '^[0-9]{6}$' then\n raise exception 'O PIN precisa ter exatamente 6 d\u00EDgitos.' using errcode = '22023';\n end if;\n\n select * into v_auth from public.plg_tables_authorizers a\n where a.id = p_authorizer_id and a.tenant_id = v_tenant;\n if not found then\n raise exception 'Autorizador n\u00E3o encontrado.' using errcode = 'P0002';\n end if;\n\n if v_auth.user_id is distinct from auth.uid()\n and not app.has_permission('tables.manage', v_auth.unit_id) then\n raise exception 'S\u00F3 a pr\u00F3pria pessoa ou quem gerencia o sal\u00E3o troca este PIN.'\n using errcode = '42501';\n end if;\n\n if to_regprocedure('extensions.crypt(text,text)') is not null then\n execute 'select extensions.crypt($1, extensions.gen_salt(''bf'', 8))'\n into v_hash using p_pin;\n elsif to_regprocedure('public.crypt(text,text)') is not null then\n execute 'select public.crypt($1, public.gen_salt(''bf'', 8))'\n into v_hash using p_pin;\n else\n raise exception 'comanda_set_authorizer_pin: pgcrypto n\u00E3o est\u00E1 instalado'\n using errcode = '42883';\n end if;\n\n update public.plg_tables_authorizers\n set pin_hash = v_hash, failed_attempts = 0, locked_until = null, updated_at = now()\n where id = p_authorizer_id and tenant_id = v_tenant;\nend $$;\n\ncomment on function public.comanda_set_authorizer_pin(uuid, text) is\n 'Grava o PIN do autorizador com bcrypt. S\u00F3 o pr\u00F3prio autorizador ou quem tem tables.manage na unidade dele (037).';\n\nrevoke all on function public.comanda_set_authorizer_pin(uuid, text) from public, anon;\ngrant execute on function public.comanda_set_authorizer_pin(uuid, text) to authenticated;\n";
|
|
37
37
|
export declare const MIGRATION_038_O_AUTORIZADOR_E_UM_LOGIN_COM_NOME = "-- plg_tables_authorizers.user_id is the authorizer's LOGIN (016's own comment,\n-- and what 037 compares to auth.uid()), but v_comanda_authorizers looked the\n-- name up as if it were a people.id, so a real authorizer showed as\n-- \"Autorizador\". The name now comes from the member's person record.\n--\n-- Same columns, same tenant fence, same grant. Idempotent.\ncreate or replace view public.v_comanda_authorizers as\nselect\n a.id, a.tenant_id, a.unit_id, a.user_id,\n coalesce(nullif(a.label, ''), p.name, 'Autorizador') as label,\n a.allows_discount, a.allows_service_charge, a.allows_cancel, a.allows_courtesy,\n a.max_discount_percent,\n (a.pin_hash is not null) as has_pin,\n (a.locked_until is not null and a.locked_until > now()) as is_locked\nfrom public.plg_tables_authorizers a\nleft join app.memberships m on m.tenant_id = a.tenant_id and m.user_id = a.user_id\nleft join public.people p on p.id = m.person_id\nwhere a.is_active\n and a.tenant_id = (select app.current_tenant_id());\n\ngrant select on public.v_comanda_authorizers to authenticated;\n";
|
|
38
|
+
export declare const MIGRATION_039_AN_ORDER_CHANGE_RINGS_THE_FLOOR_BELL = "-- ---------------------------------------------------------------------------\n-- 039_an_order_change_rings_the_floor_bell.sql\n--\n-- The PDV re-reads its tickets when `salao:<tenant>` rings (useFloorBell in\n-- @fayz-ai/pos). Until now only a storefront order rang it (shop 0123), so an\n-- order that arrived from iFood, 99Food or Keeta through the integration\n-- service, or one whose status changed outside this tablet (cancelled by the\n-- customer, confirmed in another screen, cancelled by an admin), stayed off\n-- the delivery board until someone reloaded the page.\n--\n-- So a new order, and every status change of one, rings the same bell. Same\n-- rules as 035 and 0123: a public topic and an EMPTY payload; whoever hears it\n-- re-reads through RLS. Guarded on `realtime.send` and wrapped so a failing\n-- bell never fails the write: the order is the point, the bell a convenience.\n--\n-- Idempotent and replay-safe.\n-- ---------------------------------------------------------------------------\nCREATE OR REPLACE FUNCTION public.plg_tables_ring_for_an_order()\nRETURNS trigger\nLANGUAGE plpgsql\nSECURITY DEFINER\nSET search_path = ''\nAS $$\nBEGIN\n IF NEW.tenant_id IS NULL OR to_regproc('realtime.send') IS NULL THEN\n RETURN NEW;\n END IF;\n BEGIN\n PERFORM realtime.send('{}'::jsonb, 'salao', 'salao:' || NEW.tenant_id::text, false);\n EXCEPTION WHEN OTHERS THEN\n RAISE WARNING 'plg_tables_ring_for_an_order: %', SQLERRM;\n END;\n RETURN NEW;\nEND $$;\n\nCOMMENT ON FUNCTION public.plg_tables_ring_for_an_order() IS\n 'Rings `salao:<tenant>` when an order is created or its status changes, so open PDVs re-read their tickets. No payload (039).';\n\nREVOKE ALL ON FUNCTION public.plg_tables_ring_for_an_order() FROM PUBLIC, anon, authenticated;\n\nDROP TRIGGER IF EXISTS plg_tables_order_rings_the_floor ON public.orders;\nCREATE TRIGGER plg_tables_order_rings_the_floor\n AFTER INSERT OR UPDATE OF status ON public.orders\n FOR EACH ROW\n EXECUTE FUNCTION public.plg_tables_ring_for_an_order();\n";
|
|
38
39
|
export declare const MIGRATIONS: Array<{
|
|
39
40
|
id: string;
|
|
40
41
|
sql: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/migrations/index.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,wBAAwB,40QAuJpC,CAAA;AAED,eAAO,MAAM,qBAAqB,83hBAkSjC,CAAA;AAED,eAAO,MAAM,+CAA+C,kzaAwP3D,CAAA;AAED,eAAO,MAAM,4CAA4C,g/gBAuTxD,CAAA;AAED,eAAO,MAAM,gDAAgD,ihHA6E5D,CAAA;AAED,eAAO,MAAM,qDAAqD,gpYA2MjE,CAAA;AAED,eAAO,MAAM,kDAAkD,8rHAmF9D,CAAA;AAED,eAAO,MAAM,2CAA2C,qmgBAwMvD,CAAA;AAED,eAAO,M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