@fayz-ai/plugin-conversations 0.23.1 → 0.23.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +89 -1
- package/dist/index.js.map +1 -1
- package/dist/migrations/index.d.ts +2 -0
- package/dist/migrations/index.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -5594,6 +5594,92 @@ var MIGRATION_014_CLAIMING_TARGETS_IS_SERVER_ONLY = `-- 014_claiming_targets_is_
|
|
|
5594
5594
|
REVOKE ALL ON FUNCTION public.conversations_claim_targets(uuid, integer) FROM PUBLIC, anon, authenticated;
|
|
5595
5595
|
GRANT EXECUTE ON FUNCTION public.conversations_claim_targets(uuid, integer) TO service_role;
|
|
5596
5596
|
`;
|
|
5597
|
+
var MIGRATION_015_THE_SERVICE_DOOR_FOR_MESSAGING = `-- ============================================================================
|
|
5598
|
+
-- 015_the_service_door_for_messaging \u2014 the WhatsApp edge functions move to the
|
|
5599
|
+
-- integration service (ADR 0003 phase 2, wave 2).
|
|
5600
|
+
--
|
|
5601
|
+
-- Two kinds of table, two kinds of access:
|
|
5602
|
+
--
|
|
5603
|
+
-- * tenant tables a member already writes (conversations, messages,
|
|
5604
|
+
-- campaigns, templates): the service writes them AS the store's owner or
|
|
5605
|
+
-- as the verified caller (core migrations 210/212), under RLS. Nothing
|
|
5606
|
+
-- here.
|
|
5607
|
+
-- * service tables only a machine writes, which service_role wrote until
|
|
5608
|
+
-- now: provider credentials, channels, opt-outs, webhook events, provider
|
|
5609
|
+
-- templates, payment requests. fayz_integration gets exactly that, table
|
|
5610
|
+
-- by table, with an explicit policy. Panels keep their SELECT policies.
|
|
5611
|
+
--
|
|
5612
|
+
-- And the three server-only functions the webhooks call get EXECUTE for the
|
|
5613
|
+
-- service role (they were service_role only, 014).
|
|
5614
|
+
--
|
|
5615
|
+
-- Guarded: the role is an operator step. Replay-safe.
|
|
5616
|
+
-- ============================================================================
|
|
5617
|
+
|
|
5618
|
+
DO $$
|
|
5619
|
+
DECLARE
|
|
5620
|
+
t text;
|
|
5621
|
+
f text;
|
|
5622
|
+
BEGIN
|
|
5623
|
+
IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'fayz_integration') THEN
|
|
5624
|
+
RETURN;
|
|
5625
|
+
END IF;
|
|
5626
|
+
|
|
5627
|
+
FOREACH t IN ARRAY ARRAY[
|
|
5628
|
+
'plg_conversations_providers',
|
|
5629
|
+
'plg_conversations_channels',
|
|
5630
|
+
'plg_conversations_optouts',
|
|
5631
|
+
'plg_conversations_webhook_events',
|
|
5632
|
+
'plg_automations_provider_templates',
|
|
5633
|
+
'plg_conversations_payment_requests'
|
|
5634
|
+
] LOOP
|
|
5635
|
+
IF to_regclass('public.' || t) IS NULL THEN CONTINUE; END IF;
|
|
5636
|
+
EXECUTE format('GRANT SELECT, INSERT, UPDATE, DELETE ON public.%I TO fayz_integration', t);
|
|
5637
|
+
EXECUTE format('DROP POLICY IF EXISTS %I ON public.%I', t || '_service', t);
|
|
5638
|
+
EXECUTE format('CREATE POLICY %I ON public.%I FOR ALL TO fayz_integration USING (true) WITH CHECK (true)', t || '_service', t);
|
|
5639
|
+
END LOOP;
|
|
5640
|
+
|
|
5641
|
+
FOREACH f IN ARRAY ARRAY[
|
|
5642
|
+
'public.conversations_claim_targets(uuid, integer)',
|
|
5643
|
+
'public.plg_booking_apply_channel_reply(uuid, text, uuid)',
|
|
5644
|
+
'public.plg_conversations_match_by_phone(text, text, text, uuid)'
|
|
5645
|
+
] LOOP
|
|
5646
|
+
IF to_regprocedure(f) IS NOT NULL THEN
|
|
5647
|
+
EXECUTE format('GRANT EXECUTE ON FUNCTION %s TO fayz_integration', f);
|
|
5648
|
+
END IF;
|
|
5649
|
+
END LOOP;
|
|
5650
|
+
END $$;
|
|
5651
|
+
`;
|
|
5652
|
+
var MIGRATION_016_A_DELIVERY_RECEIPT_FINDS_ITS_TENANT = `-- ============================================================================
|
|
5653
|
+
-- 016_a_delivery_receipt_finds_its_tenant \u2014 the Tyxter webhook moves to the
|
|
5654
|
+
-- integration service (ADR 0003 phase 2).
|
|
5655
|
+
--
|
|
5656
|
+
-- A delivery receipt names only the provider's message id. The service writes
|
|
5657
|
+
-- the inbox AS the store's owner (core 212), so it must learn the store first:
|
|
5658
|
+
-- this answers the tenant of the message that id was sent as, and nothing
|
|
5659
|
+
-- else. SECURITY DEFINER, service role only.
|
|
5660
|
+
--
|
|
5661
|
+
-- Replay-safe: CREATE OR REPLACE; guarded grants.
|
|
5662
|
+
-- ============================================================================
|
|
5663
|
+
|
|
5664
|
+
CREATE OR REPLACE FUNCTION public.conversations_message_tenant(p_provider_message_id text) RETURNS uuid
|
|
5665
|
+
LANGUAGE sql STABLE SECURITY DEFINER SET search_path TO ''
|
|
5666
|
+
AS $function$
|
|
5667
|
+
SELECT m.tenant_id
|
|
5668
|
+
FROM public.plg_conversation_messages m
|
|
5669
|
+
WHERE m.provider_message_id = p_provider_message_id
|
|
5670
|
+
ORDER BY m.at DESC NULLS LAST
|
|
5671
|
+
LIMIT 1;
|
|
5672
|
+
$function$;
|
|
5673
|
+
|
|
5674
|
+
DO $$
|
|
5675
|
+
BEGIN
|
|
5676
|
+
REVOKE ALL ON FUNCTION public.conversations_message_tenant(text) FROM PUBLIC;
|
|
5677
|
+
IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'anon') THEN REVOKE ALL ON FUNCTION public.conversations_message_tenant(text) FROM anon; END IF;
|
|
5678
|
+
IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'authenticated') THEN REVOKE ALL ON FUNCTION public.conversations_message_tenant(text) FROM authenticated; END IF;
|
|
5679
|
+
IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'service_role') THEN GRANT EXECUTE ON FUNCTION public.conversations_message_tenant(text) TO service_role; END IF;
|
|
5680
|
+
IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'fayz_integration') THEN GRANT EXECUTE ON FUNCTION public.conversations_message_tenant(text) TO fayz_integration; END IF;
|
|
5681
|
+
END $$;
|
|
5682
|
+
`;
|
|
5597
5683
|
var MIGRATIONS = [
|
|
5598
5684
|
{ id: "000_baseline", sql: MIGRATION_000_BASELINE },
|
|
5599
5685
|
{ id: "001_a_caixa_sabe_quem_falou_por_ultimo", sql: MIGRATION_001_A_CAIXA_SABE_QUEM_FALOU_POR_ULTIMO },
|
|
@@ -5609,7 +5695,9 @@ var MIGRATIONS = [
|
|
|
5609
5695
|
{ id: "011_o_anuncio_e_uma_campainha_nao_um_recado", sql: MIGRATION_011_O_ANUNCIO_E_UMA_CAMPAINHA_NAO_UM_RECADO },
|
|
5610
5696
|
{ id: "012_a_rich_message_keeps_its_shape", sql: MIGRATION_012_A_RICH_MESSAGE_KEEPS_ITS_SHAPE },
|
|
5611
5697
|
{ id: "013_a_midia_fica_conosco", sql: MIGRATION_013_A_MIDIA_FICA_CONOSCO },
|
|
5612
|
-
{ id: "014_claiming_targets_is_server_only", sql: MIGRATION_014_CLAIMING_TARGETS_IS_SERVER_ONLY }
|
|
5698
|
+
{ id: "014_claiming_targets_is_server_only", sql: MIGRATION_014_CLAIMING_TARGETS_IS_SERVER_ONLY },
|
|
5699
|
+
{ id: "015_the_service_door_for_messaging", sql: MIGRATION_015_THE_SERVICE_DOOR_FOR_MESSAGING },
|
|
5700
|
+
{ id: "016_a_delivery_receipt_finds_its_tenant", sql: MIGRATION_016_A_DELIVERY_RECEIPT_FINDS_ITS_TENANT }
|
|
5613
5701
|
];
|
|
5614
5702
|
var conversationsV1SettingsTabs = [
|
|
5615
5703
|
defineSettingsTab({
|