spine-framework 0.3.31 → 0.3.32

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.
@@ -18,24 +18,8 @@ import { createClient } from '@supabase/supabase-js'
18
18
 
19
19
  // ─── ENVIRONMENT RESOLUTION ──────────────────────────────────────────────────
20
20
 
21
- const _env = (globalThis as any).process?.env || {}
22
- const supabaseUrl: string = _env.SUPABASE_URL!
23
- const supabaseServiceKey: string = _env.SUPABASE_SERVICE_ROLE_KEY!
24
- const supabaseAnonKey: string = _env.SUPABASE_ANON_KEY!
25
-
26
- /**
27
- * Active database schema name, read from `DB_SCHEMA` env var.
28
- *
29
- * Defaults to `'public'` (production schema). Set to `'v2'` only in legacy
30
- * environments. All new migrations target `public`.
31
- *
32
- * @inputSpec DB_SCHEMA: string — one of 'public' | 'v2'. Any other value is
33
- * passed through as-is and will cause runtime query errors.
34
- * @outputSpec string — schema name applied to both Supabase clients.
35
- * @sideEffects none
36
- * @calledBy adminDb, getUserDb (applied at client construction time)
37
- */
38
- const dbSchema: string = _env.DB_SCHEMA || 'public'
21
+ // Environment variables are read lazily at call time (not at module load)
22
+ // so the CLI works before .env is configured (e.g. for --help and init).
39
23
 
40
24
  // ─── CLIENTS ─────────────────────────────────────────────────────────────────
41
25
 
@@ -73,9 +57,22 @@ const dbSchema: string = _env.DB_SCHEMA || 'public'
73
57
  * // Only use adminDb if your custom code runs as a system/cron principal
74
58
  * ```
75
59
  */
76
- export const adminDb = createClient(supabaseUrl, supabaseServiceKey, {
77
- db: {
78
- schema: dbSchema
60
+ function getAdminDb() {
61
+ const url = (globalThis as any).process?.env?.SUPABASE_URL
62
+ const key = (globalThis as any).process?.env?.SUPABASE_SERVICE_ROLE_KEY
63
+ const schema = (globalThis as any).process?.env?.DB_SCHEMA || 'public'
64
+ if (!url || !key) {
65
+ throw new Error(
66
+ 'SUPABASE_URL and SUPABASE_SERVICE_ROLE_KEY must be set.\n' +
67
+ 'Add them to your .env file and run: npx spine-framework migrate'
68
+ )
69
+ }
70
+ return createClient(url, key, { db: { schema } })
71
+ }
72
+
73
+ export const adminDb = new Proxy({} as ReturnType<typeof getAdminDb>, {
74
+ get(_target, prop) {
75
+ return (getAdminDb() as any)[prop]
79
76
  }
80
77
  })
81
78
 
@@ -94,15 +91,12 @@ export const adminDb = createClient(supabaseUrl, supabaseServiceKey, {
94
91
  * @tags database, supabase, rls, authentication, user-scoped
95
92
  */
96
93
  export function getUserDb(jwt: string) {
97
- return createClient(supabaseUrl, supabaseAnonKey, {
98
- db: {
99
- schema: dbSchema
100
- },
101
- global: {
102
- headers: {
103
- Authorization: `Bearer ${jwt}`
104
- }
105
- }
94
+ const url = (globalThis as any).process?.env?.SUPABASE_URL
95
+ const anonKey = (globalThis as any).process?.env?.SUPABASE_ANON_KEY
96
+ const schema = (globalThis as any).process?.env?.DB_SCHEMA || 'public'
97
+ return createClient(url, anonKey, {
98
+ db: { schema },
99
+ global: { headers: { Authorization: `Bearer ${jwt}` } }
106
100
  })
107
101
  }
108
102
  // ─── CHUNK_END: SHARED_DB_GET_USER_DB ────────────────────────────────────────────────
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spine-framework",
3
- "version": "0.3.31",
3
+ "version": "0.3.32",
4
4
  "description": "Multi-tenant, modular application platform for modern SaaS systems",
5
5
  "bin": {
6
6
  "spine-framework": "bin/spine-framework.js"