@elevasis/core 0.34.2 → 0.35.0
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/auth/index.d.ts +74 -2
- package/dist/auth/index.js +65 -30
- package/dist/index.d.ts +60 -2
- package/dist/index.js +52 -1
- package/dist/knowledge/index.d.ts +12 -0
- package/dist/organization-model/index.d.ts +60 -2
- package/dist/organization-model/index.js +52 -1
- package/dist/test-utils/index.d.ts +12 -0
- package/dist/test-utils/index.js +51 -0
- package/package.json +1 -1
- package/src/_gen/__tests__/__snapshots__/contracts.md.snap +69 -30
- package/src/auth/multi-tenancy/index.ts +29 -26
- package/src/auth/multi-tenancy/org-id.test.ts +139 -0
- package/src/auth/multi-tenancy/org-id.ts +112 -0
- package/src/business/acquisition/api-schemas.test.ts +456 -28
- package/src/business/acquisition/ontology-validation.ts +715 -23
- package/src/execution/engine/tools/platform/storage/__tests__/storage.test.ts +997 -998
- package/src/organization-model/__tests__/domains/systems.test.ts +61 -15
- package/src/organization-model/__tests__/domains/topology.test.ts +23 -0
- package/src/organization-model/__tests__/schema.test.ts +112 -0
- package/src/organization-model/domains/systems.ts +44 -0
- package/src/organization-model/domains/topology.ts +18 -1
- package/src/organization-model/published.ts +19 -1
- package/src/organization-model/schema-refinements.ts +23 -0
- package/src/organization-model/types.ts +17 -1
- package/src/platform/constants/versions.ts +1 -1
- package/src/platform/registry/__tests__/validation.test.ts +218 -4
- package/src/platform/registry/index.ts +28 -15
- package/src/platform/registry/validation.ts +172 -2
- package/src/reference/_generated/contracts.md +44 -0
- package/src/supabase/__tests__/helpers.test.ts +92 -51
- package/src/supabase/helpers.ts +40 -20
- package/src/supabase/index.ts +52 -52
|
@@ -1,51 +1,92 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest'
|
|
2
|
-
import { sanitizePostgrestValue } from '../helpers'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
expect(sanitizePostgrestValue('
|
|
8
|
-
expect(sanitizePostgrestValue('
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
expect(sanitizePostgrestValue('
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
expect(sanitizePostgrestValue('(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
expect(sanitizePostgrestValue('
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
expect(sanitizePostgrestValue('
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
//
|
|
42
|
-
//
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
})
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { eqOrgId, sanitizePostgrestValue } from '../helpers'
|
|
3
|
+
import { brandSupabaseOrgId, brandWorkOsOrgId } from '../../auth/multi-tenancy/org-id'
|
|
4
|
+
|
|
5
|
+
describe('sanitizePostgrestValue', () => {
|
|
6
|
+
it('passes through normal search strings unchanged', () => {
|
|
7
|
+
expect(sanitizePostgrestValue('hello')).toBe('hello')
|
|
8
|
+
expect(sanitizePostgrestValue('John Doe')).toBe('John Doe')
|
|
9
|
+
expect(sanitizePostgrestValue('test@example.com')).toBe('test@example.com')
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
it('strips commas that would split .or() conditions', () => {
|
|
13
|
+
expect(sanitizePostgrestValue('foo,bar')).toBe('foobar')
|
|
14
|
+
expect(sanitizePostgrestValue('a,b,c')).toBe('abc')
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
it('strips parentheses that would create logical grouping', () => {
|
|
18
|
+
expect(sanitizePostgrestValue('foo(bar)')).toBe('foobar')
|
|
19
|
+
expect(sanitizePostgrestValue('(test)')).toBe('test')
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('strips all special chars together', () => {
|
|
23
|
+
expect(sanitizePostgrestValue('test,name.eq.admin()')).toBe('testname.eq.admin')
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('preserves dots (safe in ilike values)', () => {
|
|
27
|
+
expect(sanitizePostgrestValue('example.com')).toBe('example.com')
|
|
28
|
+
expect(sanitizePostgrestValue('v1.2.3')).toBe('v1.2.3')
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it('preserves percent and underscore (SQL wildcards used intentionally)', () => {
|
|
32
|
+
expect(sanitizePostgrestValue('100%')).toBe('100%')
|
|
33
|
+
expect(sanitizePostgrestValue('test_value')).toBe('test_value')
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it('handles empty string', () => {
|
|
37
|
+
expect(sanitizePostgrestValue('')).toBe('')
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it('prevents the specific attack vector: injecting extra filter conditions', () => {
|
|
41
|
+
// Without sanitization, this would produce:
|
|
42
|
+
// name.ilike.%test,name.eq.secret%,domain.ilike.%test,name.eq.secret%
|
|
43
|
+
// PostgREST would parse "name.eq.secret%" as an additional filter condition
|
|
44
|
+
const malicious = 'test,name.eq.secret'
|
|
45
|
+
const sanitized = sanitizePostgrestValue(malicious)
|
|
46
|
+
const filter = `name.ilike.%${sanitized}%,domain.ilike.%${sanitized}%`
|
|
47
|
+
|
|
48
|
+
// Should produce exactly 2 conditions (one comma separator)
|
|
49
|
+
const topLevelCommas = filter.split(',').length - 1
|
|
50
|
+
expect(topLevelCommas).toBe(1)
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
/** Minimal stand-in for a PostgREST filter builder: records `.eq` calls, returns itself for chaining. */
|
|
55
|
+
function createMockQuery() {
|
|
56
|
+
const calls: Array<[string, string]> = []
|
|
57
|
+
const query = {
|
|
58
|
+
calls,
|
|
59
|
+
eq(column: 'organization_id', value: string) {
|
|
60
|
+
calls.push([column, value])
|
|
61
|
+
return query
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return query
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
describe('eqOrgId', () => {
|
|
68
|
+
it('applies an organization_id equality filter and returns the same builder for chaining', () => {
|
|
69
|
+
const query = createMockQuery()
|
|
70
|
+
const id = brandSupabaseOrgId('2ac228f7-a0a1-49f9-920e-8a348f5253d3')
|
|
71
|
+
|
|
72
|
+
const result = eqOrgId(query, id)
|
|
73
|
+
|
|
74
|
+
expect(result).toBe(query)
|
|
75
|
+
expect(query.calls).toEqual([['organization_id', id]])
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
it('rejects the dual-org-ID swap at compile time', () => {
|
|
79
|
+
// Compile-time guard. The standing CI gate lives at the Supabase-direct call sites in
|
|
80
|
+
// command-center (which `check-types`), since @repo/core excludes test files from check-types
|
|
81
|
+
// (see memory: reference_package_test_typecheck). These assertions document + dev-hook-enforce it.
|
|
82
|
+
const query = createMockQuery()
|
|
83
|
+
const workOsId = brandWorkOsOrgId('org_01K64D59CA5J3PJCWJFQV87PPN')
|
|
84
|
+
|
|
85
|
+
// @ts-expect-error a WorkOsOrgId must not be accepted where a SupabaseOrgId is required
|
|
86
|
+
eqOrgId(query, workOsId)
|
|
87
|
+
// @ts-expect-error a raw string must not be accepted either
|
|
88
|
+
eqOrgId(query, 'plain-string')
|
|
89
|
+
|
|
90
|
+
expect(query.calls).toHaveLength(2)
|
|
91
|
+
})
|
|
92
|
+
})
|
package/src/supabase/helpers.ts
CHANGED
|
@@ -1,20 +1,40 @@
|
|
|
1
|
-
import type { Database, Tables, TablesInsert, TablesUpdate } from './database.types'
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export type
|
|
5
|
-
export type
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
import type { Database, Tables, TablesInsert, TablesUpdate } from './database.types'
|
|
2
|
+
import type { SupabaseOrgId } from '../auth/multi-tenancy/org-id'
|
|
3
|
+
|
|
4
|
+
export type TableRow<T extends keyof Database['public']['Tables']> = Tables<T>
|
|
5
|
+
export type TableInsert<T extends keyof Database['public']['Tables']> = TablesInsert<T>
|
|
6
|
+
export type TableUpdate<T extends keyof Database['public']['Tables']> = TablesUpdate<T>
|
|
7
|
+
|
|
8
|
+
export type SupabaseFunction<T extends keyof Database['public']['Functions']> = Database['public']['Functions'][T]
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Strip characters that have special meaning in PostgREST filter syntax.
|
|
12
|
+
* Use on user-supplied search strings before interpolating into `.or()` filter expressions.
|
|
13
|
+
*
|
|
14
|
+
* PostgREST uses `,` as the OR separator and `(` / `)` for logical grouping.
|
|
15
|
+
* The supabase-js `.or()` method passes strings as-is with no escaping.
|
|
16
|
+
*/
|
|
17
|
+
export function sanitizePostgrestValue(value: string): string {
|
|
18
|
+
return value.replace(/[,()]/g, '')
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Typed seam for organization-scoped Supabase filters.
|
|
23
|
+
*
|
|
24
|
+
* Supabase's `.eq()` accepts any string, so `.eq('organization_id', workOsOrgId)` compiles
|
|
25
|
+
* cleanly even though the column holds the Supabase UUID — the exact dual-org-ID swap we want
|
|
26
|
+
* to prevent. Routing org filters through this helper forces a `SupabaseOrgId`, turning that
|
|
27
|
+
* swap into a compile error while leaving the query-builder chain otherwise unchanged.
|
|
28
|
+
*
|
|
29
|
+
* The structural `Q` constraint matches any PostgREST filter builder (its `.eq` returns `this`),
|
|
30
|
+
* so the helper is independent of the supabase-js generic shape.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* let query = supabase.from('acq_companies').select('*')
|
|
34
|
+
* query = eqOrgId(query, currentSupabaseOrganizationId) // currentSupabaseOrganizationId: SupabaseOrgId
|
|
35
|
+
*/
|
|
36
|
+
export function eqOrgId<Q extends { eq(column: 'organization_id', value: string): Q }>(query: Q, id: SupabaseOrgId): Q {
|
|
37
|
+
return query.eq('organization_id', id)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type UpsertUserProfileResult = SupabaseFunction<'upsert_user_profile'>['Returns'][0]
|
package/src/supabase/index.ts
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
import type { Database, Tables, TablesInsert, TablesUpdate } from './database.types'
|
|
2
|
-
|
|
3
|
-
export type { Database, Tables, TablesInsert, TablesUpdate, Enums, CompositeTypes, Json } from './database.types'
|
|
4
|
-
|
|
5
|
-
export { Constants } from './database.types'
|
|
6
|
-
|
|
7
|
-
export type SupabaseClient = import('@supabase/supabase-js').SupabaseClient<Database>
|
|
8
|
-
|
|
9
|
-
// Note: supabaseClient is a server-only export available via @repo/core/server
|
|
10
|
-
// DO NOT export it from the main entry point to prevent browser bundling
|
|
11
|
-
|
|
12
|
-
export type SupabaseUserProfile = Tables<'users'>
|
|
13
|
-
export type SupabaseOrganization = Tables<'organizations'>
|
|
14
|
-
export type SupabaseOrgMembership = Tables<'org_memberships'>
|
|
15
|
-
export type SupabaseTaskSchedule = Tables<'task_schedules'>
|
|
16
|
-
/** @deprecated Use SupabaseTaskSchedule instead. Alias for backward compatibility. */
|
|
17
|
-
export type SupabaseScheduledTask = SupabaseTaskSchedule
|
|
18
|
-
export type SupabaseCommandQueue = Tables<'command_queue'>
|
|
19
|
-
export type SupabaseExecutionLogs = Tables<'execution_logs'>
|
|
20
|
-
export type SupabaseApiKey = Tables<'api_keys'>
|
|
21
|
-
/** API response type for API key list items (omits sensitive key_hash) */
|
|
22
|
-
export type ApiKeyListItem = Omit<SupabaseApiKey, 'key_hash'>
|
|
23
|
-
export type SupabaseOrganizationCredential = Tables<'credentials'>
|
|
24
|
-
|
|
25
|
-
export type SupabaseUserProfileInsert = TablesInsert<'users'>
|
|
26
|
-
export type SupabaseOrganizationInsert = TablesInsert<'organizations'>
|
|
27
|
-
export type SupabaseTaskScheduleInsert = TablesInsert<'task_schedules'>
|
|
28
|
-
/** @deprecated Use SupabaseTaskScheduleInsert instead. Alias for backward compatibility. */
|
|
29
|
-
export type SupabaseScheduledTaskInsert = SupabaseTaskScheduleInsert
|
|
30
|
-
export type SupabaseCommandQueueInsert = TablesInsert<'command_queue'>
|
|
31
|
-
export type SupabaseApiKeyInsert = TablesInsert<'api_keys'>
|
|
32
|
-
export type SupabaseExecutionLogsInsert = TablesInsert<'execution_logs'>
|
|
33
|
-
export type SupabaseOrganizationCredentialInsert = TablesInsert<'credentials'>
|
|
34
|
-
|
|
35
|
-
export type SupabaseUserProfileUpdate = TablesUpdate<'users'>
|
|
36
|
-
export type SupabaseOrganizationUpdate = TablesUpdate<'organizations'>
|
|
37
|
-
export type SupabaseTaskScheduleUpdate = TablesUpdate<'task_schedules'>
|
|
38
|
-
/** @deprecated Use SupabaseTaskScheduleUpdate instead. Alias for backward compatibility. */
|
|
39
|
-
export type SupabaseScheduledTaskUpdate = SupabaseTaskScheduleUpdate
|
|
40
|
-
export type SupabaseCommandQueueUpdate = TablesUpdate<'command_queue'>
|
|
41
|
-
export type SupabaseApiKeyUpdate = TablesUpdate<'api_keys'>
|
|
42
|
-
export type SupabaseExecutionLogsUpdate = TablesUpdate<'execution_logs'>
|
|
43
|
-
export type SupabaseOrganizationCredentialUpdate = TablesUpdate<'credentials'>
|
|
44
|
-
|
|
45
|
-
// Export helper types and utilities
|
|
46
|
-
export type { UpsertUserProfileResult } from './helpers'
|
|
47
|
-
export { sanitizePostgrestValue } from './helpers'
|
|
48
|
-
|
|
49
|
-
// Composite types for joined queries
|
|
50
|
-
export type SupabaseMembershipWithOrganization = SupabaseOrgMembership & {
|
|
51
|
-
organization: SupabaseOrganization | null
|
|
52
|
-
}
|
|
1
|
+
import type { Database, Tables, TablesInsert, TablesUpdate } from './database.types'
|
|
2
|
+
|
|
3
|
+
export type { Database, Tables, TablesInsert, TablesUpdate, Enums, CompositeTypes, Json } from './database.types'
|
|
4
|
+
|
|
5
|
+
export { Constants } from './database.types'
|
|
6
|
+
|
|
7
|
+
export type SupabaseClient = import('@supabase/supabase-js').SupabaseClient<Database>
|
|
8
|
+
|
|
9
|
+
// Note: supabaseClient is a server-only export available via @repo/core/server
|
|
10
|
+
// DO NOT export it from the main entry point to prevent browser bundling
|
|
11
|
+
|
|
12
|
+
export type SupabaseUserProfile = Tables<'users'>
|
|
13
|
+
export type SupabaseOrganization = Tables<'organizations'>
|
|
14
|
+
export type SupabaseOrgMembership = Tables<'org_memberships'>
|
|
15
|
+
export type SupabaseTaskSchedule = Tables<'task_schedules'>
|
|
16
|
+
/** @deprecated Use SupabaseTaskSchedule instead. Alias for backward compatibility. */
|
|
17
|
+
export type SupabaseScheduledTask = SupabaseTaskSchedule
|
|
18
|
+
export type SupabaseCommandQueue = Tables<'command_queue'>
|
|
19
|
+
export type SupabaseExecutionLogs = Tables<'execution_logs'>
|
|
20
|
+
export type SupabaseApiKey = Tables<'api_keys'>
|
|
21
|
+
/** API response type for API key list items (omits sensitive key_hash) */
|
|
22
|
+
export type ApiKeyListItem = Omit<SupabaseApiKey, 'key_hash'>
|
|
23
|
+
export type SupabaseOrganizationCredential = Tables<'credentials'>
|
|
24
|
+
|
|
25
|
+
export type SupabaseUserProfileInsert = TablesInsert<'users'>
|
|
26
|
+
export type SupabaseOrganizationInsert = TablesInsert<'organizations'>
|
|
27
|
+
export type SupabaseTaskScheduleInsert = TablesInsert<'task_schedules'>
|
|
28
|
+
/** @deprecated Use SupabaseTaskScheduleInsert instead. Alias for backward compatibility. */
|
|
29
|
+
export type SupabaseScheduledTaskInsert = SupabaseTaskScheduleInsert
|
|
30
|
+
export type SupabaseCommandQueueInsert = TablesInsert<'command_queue'>
|
|
31
|
+
export type SupabaseApiKeyInsert = TablesInsert<'api_keys'>
|
|
32
|
+
export type SupabaseExecutionLogsInsert = TablesInsert<'execution_logs'>
|
|
33
|
+
export type SupabaseOrganizationCredentialInsert = TablesInsert<'credentials'>
|
|
34
|
+
|
|
35
|
+
export type SupabaseUserProfileUpdate = TablesUpdate<'users'>
|
|
36
|
+
export type SupabaseOrganizationUpdate = TablesUpdate<'organizations'>
|
|
37
|
+
export type SupabaseTaskScheduleUpdate = TablesUpdate<'task_schedules'>
|
|
38
|
+
/** @deprecated Use SupabaseTaskScheduleUpdate instead. Alias for backward compatibility. */
|
|
39
|
+
export type SupabaseScheduledTaskUpdate = SupabaseTaskScheduleUpdate
|
|
40
|
+
export type SupabaseCommandQueueUpdate = TablesUpdate<'command_queue'>
|
|
41
|
+
export type SupabaseApiKeyUpdate = TablesUpdate<'api_keys'>
|
|
42
|
+
export type SupabaseExecutionLogsUpdate = TablesUpdate<'execution_logs'>
|
|
43
|
+
export type SupabaseOrganizationCredentialUpdate = TablesUpdate<'credentials'>
|
|
44
|
+
|
|
45
|
+
// Export helper types and utilities
|
|
46
|
+
export type { UpsertUserProfileResult } from './helpers'
|
|
47
|
+
export { sanitizePostgrestValue, eqOrgId } from './helpers'
|
|
48
|
+
|
|
49
|
+
// Composite types for joined queries
|
|
50
|
+
export type SupabaseMembershipWithOrganization = SupabaseOrgMembership & {
|
|
51
|
+
organization: SupabaseOrganization | null
|
|
52
|
+
}
|