@soulbatical/tetra-dev-toolkit 1.15.0 → 1.15.1

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.
@@ -48,7 +48,9 @@ const RULES = [
48
48
  const authWhitelist = [
49
49
  'auth_org_id', 'auth_uid', 'auth_role', 'auth_user_role',
50
50
  'auth_admin_organizations', 'auth_user_id', 'requesting_user_id',
51
- 'get_auth_org_id', 'get_current_user_id'
51
+ 'get_auth_org_id', 'get_current_user_id',
52
+ 'auth_user_organizations', 'auth_creator_organizations',
53
+ 'auth_organization_id', 'auth_is_admin', 'auth_is_superadmin'
52
54
  ]
53
55
  return !authWhitelist.includes(funcName)
54
56
  },
@@ -74,9 +76,22 @@ const RULES = [
74
76
  pattern: /DROP\s+POLICY\s+(?:IF\s+EXISTS\s+)?["']?(\w+)["']?\s+ON\s+(?:public\.)?(\w+)/gi,
75
77
  message: (match) => `DROP POLICY "${match[1]}" on "${match[2]}" — removes security. Ensure a replacement policy exists in the same migration.`,
76
78
  test: (match, fullContent) => {
79
+ const table = match[2]
77
80
  // OK if there's a CREATE POLICY in the same migration for the same table
78
- const createPattern = new RegExp(`CREATE\\s+POLICY.*ON\\s+(?:public\\.)?${match[2]}`, 'i')
79
- return !createPattern.test(fullContent)
81
+ const createPattern = new RegExp(`CREATE\\s+POLICY.*ON\\s+(?:public\\.)?${table}`, 'i')
82
+ if (createPattern.test(fullContent)) return false
83
+ // OK if there's a DO $$ block that references the table (dynamic policy creation)
84
+ const doBlockPattern = new RegExp(`DO\\s+\\$\\$[\\s\\S]*?['"]${table}['"][\\s\\S]*?\\$\\$`, 'i')
85
+ if (doBlockPattern.test(fullContent)) return false
86
+ // OK if DROP POLICY IF EXISTS (safe — only drops if present)
87
+ const dropIfExists = new RegExp(`DROP\\s+POLICY\\s+IF\\s+EXISTS`, 'i')
88
+ const matchStr = match[0]
89
+ if (dropIfExists.test(matchStr)) {
90
+ // Check if ANY policy creation exists for this table (even dynamic)
91
+ const anyCreate = new RegExp(`(CREATE\\s+POLICY|EXECUTE\\s+format.*CREATE\\s+POLICY)`, 'i')
92
+ if (anyCreate.test(fullContent)) return false
93
+ }
94
+ return true
80
95
  },
81
96
  fix: (match) => `-- Add replacement policy:\n-- CREATE POLICY "${match[1]}" ON ${match[2]} FOR ALL USING (organization_id = auth_org_id());`
82
97
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soulbatical/tetra-dev-toolkit",
3
- "version": "1.15.0",
3
+ "version": "1.15.1",
4
4
  "publishConfig": {
5
5
  "access": "restricted"
6
6
  },