spine-framework 0.3.41 → 0.3.43
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.
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { createClient } from '@supabase/supabase-js'
|
|
18
|
+
import WebSocket from 'ws'
|
|
18
19
|
|
|
19
20
|
// ─── ENVIRONMENT RESOLUTION ──────────────────────────────────────────────────
|
|
20
21
|
|
|
@@ -61,7 +62,8 @@ const dbSchema: string = _env.DB_SCHEMA || 'public'
|
|
|
61
62
|
* ```
|
|
62
63
|
*/
|
|
63
64
|
export const adminDb = createClient(supabaseUrl, supabaseServiceKey, {
|
|
64
|
-
db: { schema: dbSchema }
|
|
65
|
+
db: { schema: dbSchema },
|
|
66
|
+
realtime: { transport: WebSocket as any }
|
|
65
67
|
})
|
|
66
68
|
|
|
67
69
|
// ─── CHUNK_START: SHARED_DB_GET_USER_DB ──────────────────────────────────────────────
|
|
@@ -81,7 +83,8 @@ export const adminDb = createClient(supabaseUrl, supabaseServiceKey, {
|
|
|
81
83
|
export function getUserDb(jwt: string) {
|
|
82
84
|
return createClient(supabaseUrl, supabaseAnonKey, {
|
|
83
85
|
db: { schema: dbSchema },
|
|
84
|
-
global: { headers: { Authorization: `Bearer ${jwt}` } }
|
|
86
|
+
global: { headers: { Authorization: `Bearer ${jwt}` } },
|
|
87
|
+
realtime: { transport: WebSocket as any }
|
|
85
88
|
})
|
|
86
89
|
}
|
|
87
90
|
// ─── CHUNK_END: SHARED_DB_GET_USER_DB ────────────────────────────────────────────────
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
|
|
33
33
|
import { getUserDb, adminDb } from './db'
|
|
34
34
|
import { createClient } from '@supabase/supabase-js'
|
|
35
|
+
import WebSocket from 'ws'
|
|
35
36
|
|
|
36
37
|
// ─── AUTH CLIENT ─────────────────────────────────────────────────────────────
|
|
37
38
|
|
|
@@ -43,10 +44,8 @@ const supabase = createClient(
|
|
|
43
44
|
env.SUPABASE_URL || 'https://placeholder.supabase.co',
|
|
44
45
|
env.SUPABASE_ANON_KEY || 'placeholder',
|
|
45
46
|
{
|
|
46
|
-
auth: {
|
|
47
|
-
|
|
48
|
-
persistSession: false
|
|
49
|
-
}
|
|
47
|
+
auth: { autoRefreshToken: false, persistSession: false },
|
|
48
|
+
realtime: { transport: WebSocket as any }
|
|
50
49
|
}
|
|
51
50
|
)
|
|
52
51
|
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
-- =============================================================================
|
|
2
|
+
-- 003_auth_user_trigger.sql
|
|
3
|
+
-- Creates a people record whenever a new Supabase auth user signs up.
|
|
4
|
+
-- Run AFTER 001_seed.sql (requires spine-system account and person type).
|
|
5
|
+
--
|
|
6
|
+
-- First user ever → system_admin role (bootstrap)
|
|
7
|
+
-- Subsequent users → no role (assigned later via admin invite flow)
|
|
8
|
+
-- =============================================================================
|
|
9
|
+
|
|
10
|
+
CREATE OR REPLACE FUNCTION public.handle_new_auth_user()
|
|
11
|
+
RETURNS TRIGGER LANGUAGE plpgsql SECURITY DEFINER SET search_path = public AS $$
|
|
12
|
+
DECLARE
|
|
13
|
+
v_account_id uuid;
|
|
14
|
+
v_type_id uuid;
|
|
15
|
+
v_role_id uuid;
|
|
16
|
+
v_is_first boolean;
|
|
17
|
+
v_design_schema jsonb;
|
|
18
|
+
v_validation_schema jsonb;
|
|
19
|
+
BEGIN
|
|
20
|
+
SELECT id INTO v_account_id FROM public.accounts WHERE slug = 'spine-system' LIMIT 1;
|
|
21
|
+
SELECT id, design_schema, validation_schema
|
|
22
|
+
INTO v_type_id, v_design_schema, v_validation_schema
|
|
23
|
+
FROM public.types WHERE kind = 'person' AND slug = 'person' LIMIT 1;
|
|
24
|
+
|
|
25
|
+
IF v_account_id IS NULL OR v_type_id IS NULL THEN
|
|
26
|
+
RAISE WARNING 'handle_new_auth_user: spine-system account or person type not found — skipping people insert';
|
|
27
|
+
RETURN NEW;
|
|
28
|
+
END IF;
|
|
29
|
+
|
|
30
|
+
-- First person ever gets system_admin; subsequent users get no role
|
|
31
|
+
SELECT NOT EXISTS (SELECT 1 FROM public.people LIMIT 1) INTO v_is_first;
|
|
32
|
+
IF v_is_first THEN
|
|
33
|
+
SELECT id INTO v_role_id FROM public.roles WHERE slug = 'system_admin' LIMIT 1;
|
|
34
|
+
END IF;
|
|
35
|
+
|
|
36
|
+
INSERT INTO public.people (
|
|
37
|
+
id,
|
|
38
|
+
auth_uid,
|
|
39
|
+
email,
|
|
40
|
+
full_name,
|
|
41
|
+
account_id,
|
|
42
|
+
type_id,
|
|
43
|
+
role_id,
|
|
44
|
+
is_active,
|
|
45
|
+
design_schema,
|
|
46
|
+
validation_schema
|
|
47
|
+
) VALUES (
|
|
48
|
+
NEW.id,
|
|
49
|
+
NEW.id,
|
|
50
|
+
NEW.email,
|
|
51
|
+
COALESCE(NEW.raw_user_meta_data->>'full_name', split_part(NEW.email, '@', 1)),
|
|
52
|
+
v_account_id,
|
|
53
|
+
v_type_id,
|
|
54
|
+
v_role_id,
|
|
55
|
+
true,
|
|
56
|
+
v_design_schema,
|
|
57
|
+
COALESCE(v_validation_schema, '{}'::jsonb)
|
|
58
|
+
)
|
|
59
|
+
ON CONFLICT (id) DO NOTHING;
|
|
60
|
+
|
|
61
|
+
RETURN NEW;
|
|
62
|
+
END;
|
|
63
|
+
$$;
|
|
64
|
+
|
|
65
|
+
CREATE OR REPLACE TRIGGER on_auth_user_created
|
|
66
|
+
AFTER INSERT ON auth.users
|
|
67
|
+
FOR EACH ROW EXECUTE FUNCTION public.handle_new_auth_user();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spine-framework",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.43",
|
|
4
4
|
"description": "Multi-tenant, modular application platform for modern SaaS systems",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
".framework/migrations/002_rls_and_functions.sql",
|
|
20
20
|
".framework/migrations/003_system_data.sql",
|
|
21
21
|
".framework/migrations/004_enhancements.sql",
|
|
22
|
+
".framework/migrations/005_auth_user_trigger.sql",
|
|
22
23
|
".framework/public/",
|
|
23
24
|
".framework/scripts/",
|
|
24
25
|
".framework/seeds/",
|