@soulbatical/tetra-core 0.10.3 → 0.10.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.
- package/README.md +50 -36
- package/dist/core/createApp.d.ts.map +1 -1
- package/dist/core/createApp.js +77 -2
- package/dist/core/createApp.js.map +1 -1
- package/dist/core/dualWriteProxy.d.ts +7 -2
- package/dist/core/dualWriteProxy.d.ts.map +1 -1
- package/dist/core/dualWriteProxy.js +16 -5
- package/dist/core/dualWriteProxy.js.map +1 -1
- package/dist/core/routeContext.d.ts +24 -0
- package/dist/core/routeContext.d.ts.map +1 -1
- package/dist/core/routeContext.js +31 -4
- package/dist/core/routeContext.js.map +1 -1
- package/dist/core/systemDb.d.ts +2 -2
- package/dist/core/systemDb.js +2 -2
- package/dist/generators.d.ts +4 -10
- package/dist/generators.d.ts.map +1 -1
- package/dist/generators.js +3 -7
- package/dist/generators.js.map +1 -1
- package/dist/index.d.ts +9 -31
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -27
- package/dist/index.js.map +1 -1
- package/dist/middleware/validateBody.d.ts.map +1 -1
- package/dist/middleware/validateBody.js +51 -8
- package/dist/middleware/validateBody.js.map +1 -1
- package/dist/shared/rfc7807ErrorResponse.d.ts +7 -0
- package/dist/shared/rfc7807ErrorResponse.d.ts.map +1 -1
- package/dist/shared/rfc7807ErrorResponse.js +19 -5
- package/dist/shared/rfc7807ErrorResponse.js.map +1 -1
- package/dist/shared/telegram/routes.d.ts +6 -1
- package/dist/shared/telegram/routes.d.ts.map +1 -1
- package/dist/shared/telegram/routes.js +68 -18
- package/dist/shared/telegram/routes.js.map +1 -1
- package/dist/shared/telegram/types.d.ts +19 -1
- package/dist/shared/telegram/types.d.ts.map +1 -1
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +15 -6
- package/dist/utils/logger.js.map +1 -1
- package/package.json +12 -42
- package/src/shared/email/migrations/000_create_email_logs.sql +0 -27
- package/src/shared/email/migrations/001_create_email_templates.sql +0 -27
- package/src/shared/email/migrations/002_add_rls_baseline_policies.sql +0 -37
- package/src/shared/email/migrations/003_create_gmail_accounts.sql +0 -82
- package/src/shared/email/migrations/004_add_email_logs_tracking_columns.sql +0 -15
- package/src/shared/mcp/migrations/001_mcp_api_tokens.sql +0 -21
- package/src/shared/mcp/migrations/002_mcp_audit_log.sql +0 -16
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
-- Migration: Create gmail_accounts table for OAuth2 Gmail integration
|
|
2
|
-
-- Used by: EmailService (gmail transport), Gmail read/search/attachment tools
|
|
3
|
-
-- Tokens are encrypted with AES-256-GCM (ENCRYPTION_MASTER_KEY env var)
|
|
4
|
-
|
|
5
|
-
CREATE TABLE IF NOT EXISTS gmail_accounts (
|
|
6
|
-
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
7
|
-
|
|
8
|
-
-- Organization scope
|
|
9
|
-
organization_id UUID NOT NULL REFERENCES organizations(id) ON DELETE CASCADE,
|
|
10
|
-
|
|
11
|
-
-- User scope (supports multiple accounts per user)
|
|
12
|
-
user_id UUID NOT NULL REFERENCES auth.users(id) ON DELETE CASCADE,
|
|
13
|
-
|
|
14
|
-
-- Gmail account email
|
|
15
|
-
email TEXT NOT NULL,
|
|
16
|
-
|
|
17
|
-
-- Encrypted OAuth2 tokens (AES-256-GCM)
|
|
18
|
-
access_token_encrypted TEXT NOT NULL,
|
|
19
|
-
refresh_token_encrypted TEXT NOT NULL,
|
|
20
|
-
token_expires_at TIMESTAMPTZ NOT NULL,
|
|
21
|
-
|
|
22
|
-
-- Granted scopes
|
|
23
|
-
scopes TEXT[] NOT NULL DEFAULT ARRAY[
|
|
24
|
-
'https://www.googleapis.com/auth/gmail.send',
|
|
25
|
-
'https://www.googleapis.com/auth/gmail.readonly'
|
|
26
|
-
],
|
|
27
|
-
|
|
28
|
-
-- Status
|
|
29
|
-
is_active BOOLEAN NOT NULL DEFAULT true,
|
|
30
|
-
|
|
31
|
-
-- Timestamps
|
|
32
|
-
created_at TIMESTAMPTZ DEFAULT now(),
|
|
33
|
-
updated_at TIMESTAMPTZ DEFAULT now(),
|
|
34
|
-
|
|
35
|
-
-- One Gmail account per user+email combination
|
|
36
|
-
UNIQUE(user_id, email)
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
-- Indexes
|
|
40
|
-
CREATE INDEX IF NOT EXISTS gmail_accounts_org_idx ON gmail_accounts (organization_id);
|
|
41
|
-
CREATE INDEX IF NOT EXISTS gmail_accounts_user_idx ON gmail_accounts (user_id);
|
|
42
|
-
CREATE INDEX IF NOT EXISTS gmail_accounts_active_idx ON gmail_accounts (organization_id, is_active) WHERE is_active = true;
|
|
43
|
-
|
|
44
|
-
-- Updated_at trigger (uses existing function if available, creates if not)
|
|
45
|
-
DO $$ BEGIN
|
|
46
|
-
CREATE OR REPLACE FUNCTION update_updated_at()
|
|
47
|
-
RETURNS TRIGGER AS $fn$
|
|
48
|
-
BEGIN
|
|
49
|
-
NEW.updated_at = now();
|
|
50
|
-
RETURN NEW;
|
|
51
|
-
END;
|
|
52
|
-
$fn$ LANGUAGE plpgsql;
|
|
53
|
-
EXCEPTION WHEN duplicate_function THEN NULL;
|
|
54
|
-
END $$;
|
|
55
|
-
|
|
56
|
-
CREATE TRIGGER gmail_accounts_updated_at
|
|
57
|
-
BEFORE UPDATE ON gmail_accounts
|
|
58
|
-
FOR EACH ROW EXECUTE FUNCTION update_updated_at();
|
|
59
|
-
|
|
60
|
-
-- RLS
|
|
61
|
-
ALTER TABLE gmail_accounts ENABLE ROW LEVEL SECURITY;
|
|
62
|
-
|
|
63
|
-
-- Read: users see their own accounts, org admins see all org accounts
|
|
64
|
-
CREATE POLICY "gmail_accounts_select" ON gmail_accounts FOR SELECT USING (
|
|
65
|
-
user_id = auth.uid()
|
|
66
|
-
OR organization_id IN (
|
|
67
|
-
SELECT om.organization_id FROM organization_members om
|
|
68
|
-
WHERE om.user_id = auth.uid() AND om.role = 'admin'
|
|
69
|
-
)
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
-- Write: service_role only (backend manages tokens)
|
|
73
|
-
CREATE POLICY "gmail_accounts_insert_service_role" ON gmail_accounts FOR INSERT
|
|
74
|
-
WITH CHECK (auth.role() = 'service_role');
|
|
75
|
-
|
|
76
|
-
CREATE POLICY "gmail_accounts_update_service_role" ON gmail_accounts FOR UPDATE
|
|
77
|
-
USING (auth.role() = 'service_role');
|
|
78
|
-
|
|
79
|
-
CREATE POLICY "gmail_accounts_delete_service_role" ON gmail_accounts FOR DELETE
|
|
80
|
-
USING (auth.role() = 'service_role');
|
|
81
|
-
|
|
82
|
-
COMMENT ON TABLE gmail_accounts IS 'Gmail OAuth2 accounts for email integration (send, read, search, attachments)';
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
-- ============================================
|
|
2
|
-
-- Email Logs — add tracking & categorization columns
|
|
3
|
-
-- Part of @soulbatical/tetra-core email module
|
|
4
|
-
-- ============================================
|
|
5
|
-
-- Adds: email_type, metadata, delivered_at, opened_at, clicked_at
|
|
6
|
-
-- These support Mailgun webhook tracking and email categorization.
|
|
7
|
-
|
|
8
|
-
ALTER TABLE email_logs ADD COLUMN IF NOT EXISTS email_type VARCHAR(100);
|
|
9
|
-
ALTER TABLE email_logs ADD COLUMN IF NOT EXISTS metadata JSONB DEFAULT '{}';
|
|
10
|
-
ALTER TABLE email_logs ADD COLUMN IF NOT EXISTS delivered_at TIMESTAMPTZ;
|
|
11
|
-
ALTER TABLE email_logs ADD COLUMN IF NOT EXISTS opened_at TIMESTAMPTZ;
|
|
12
|
-
ALTER TABLE email_logs ADD COLUMN IF NOT EXISTS clicked_at TIMESTAMPTZ;
|
|
13
|
-
|
|
14
|
-
CREATE INDEX IF NOT EXISTS idx_email_logs_email_type ON email_logs(email_type);
|
|
15
|
-
CREATE INDEX IF NOT EXISTS idx_email_logs_to_email ON email_logs(to_email);
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
-- MCP API tokens for online MCP access
|
|
2
|
-
-- Each token is linked to an organization for multi-tenant isolation
|
|
3
|
-
-- Token is stored as SHA-256 hash, never plaintext
|
|
4
|
-
|
|
5
|
-
CREATE TABLE IF NOT EXISTS public.mcp_api_tokens (
|
|
6
|
-
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
7
|
-
organization_id UUID NOT NULL REFERENCES organizations(id),
|
|
8
|
-
token_hash TEXT NOT NULL UNIQUE,
|
|
9
|
-
name TEXT NOT NULL DEFAULT 'Default',
|
|
10
|
-
created_by UUID REFERENCES auth.users(id),
|
|
11
|
-
is_active BOOLEAN NOT NULL DEFAULT true,
|
|
12
|
-
last_used_at TIMESTAMPTZ,
|
|
13
|
-
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
14
|
-
revoked_at TIMESTAMPTZ
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
ALTER TABLE public.mcp_api_tokens ENABLE ROW LEVEL SECURITY;
|
|
18
|
-
CREATE POLICY "Service role full access" ON public.mcp_api_tokens
|
|
19
|
-
FOR ALL TO service_role USING (true) WITH CHECK (true);
|
|
20
|
-
CREATE INDEX IF NOT EXISTS idx_mcp_api_tokens_hash ON public.mcp_api_tokens(token_hash);
|
|
21
|
-
CREATE INDEX IF NOT EXISTS idx_mcp_api_tokens_org ON public.mcp_api_tokens(organization_id);
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
-- MCP audit log for tracking tool usage per token/organization
|
|
2
|
-
|
|
3
|
-
CREATE TABLE IF NOT EXISTS public.mcp_audit_log (
|
|
4
|
-
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
5
|
-
token_id UUID REFERENCES mcp_api_tokens(id),
|
|
6
|
-
organization_id UUID NOT NULL REFERENCES organizations(id),
|
|
7
|
-
tool_name TEXT NOT NULL,
|
|
8
|
-
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
|
9
|
-
);
|
|
10
|
-
|
|
11
|
-
ALTER TABLE public.mcp_audit_log ENABLE ROW LEVEL SECURITY;
|
|
12
|
-
CREATE POLICY "Service role full access" ON public.mcp_audit_log
|
|
13
|
-
FOR ALL TO service_role USING (true) WITH CHECK (true);
|
|
14
|
-
CREATE INDEX IF NOT EXISTS idx_mcp_audit_log_org ON public.mcp_audit_log(organization_id);
|
|
15
|
-
CREATE INDEX IF NOT EXISTS idx_mcp_audit_log_token ON public.mcp_audit_log(token_id);
|
|
16
|
-
CREATE INDEX IF NOT EXISTS idx_mcp_audit_log_created ON public.mcp_audit_log(created_at DESC);
|