@elevasis/core 0.12.0 → 0.14.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.
Files changed (50) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +9 -2
  3. package/dist/organization-model/index.d.ts +1 -1
  4. package/dist/organization-model/index.js +9 -2
  5. package/dist/test-utils/index.d.ts +480 -389
  6. package/dist/test-utils/index.js +28 -2
  7. package/package.json +1 -1
  8. package/src/_gen/__tests__/__snapshots__/contracts.md.snap +2324 -0
  9. package/src/auth/multi-tenancy/credentials/__tests__/encryption.test.ts +217 -216
  10. package/src/auth/multi-tenancy/credentials/server/encryption.ts +5 -19
  11. package/src/auth/multi-tenancy/credentials/server/kek-loader.ts +3 -13
  12. package/src/auth/multi-tenancy/permissions.ts +12 -5
  13. package/src/business/acquisition/activity-events.test.ts +250 -0
  14. package/src/business/acquisition/activity-events.ts +84 -0
  15. package/src/business/acquisition/api-schemas.test.ts +1180 -0
  16. package/src/business/acquisition/api-schemas.ts +456 -235
  17. package/src/business/acquisition/crm-state-actions.test.ts +160 -0
  18. package/src/business/acquisition/derive-actions.test.ts +518 -0
  19. package/src/business/acquisition/derive-actions.ts +103 -0
  20. package/src/business/acquisition/index.ts +51 -11
  21. package/src/business/acquisition/stateful.ts +30 -0
  22. package/src/business/acquisition/types.ts +44 -77
  23. package/src/execution/engine/index.ts +4 -1
  24. package/src/execution/engine/tools/integration/server/adapters/apify/__tests__/apify-run-actor.integration.test.ts +1 -2
  25. package/src/execution/engine/tools/integration/server/adapters/attio/__tests__/attio-crud.integration.test.ts +363 -361
  26. package/src/execution/engine/tools/integration/server/adapters/attio/fetch/get-record/index.test.ts +162 -186
  27. package/src/execution/engine/tools/integration/server/adapters/attio/fetch/list-records/index.test.ts +316 -338
  28. package/src/execution/engine/tools/integration/server/adapters/gmail/gmail-adapter.ts +204 -210
  29. package/src/execution/engine/tools/integration/server/adapters/resend/fetch/send-email/index.test.ts +88 -0
  30. package/src/execution/engine/tools/integration/server/adapters/resend/fetch/send-email/index.ts +141 -134
  31. package/src/execution/engine/tools/integration/server/adapters/resend/fetch/utils/types.ts +76 -75
  32. package/src/execution/engine/tools/integration/service.test.ts +34 -9
  33. package/src/execution/engine/tools/integration/service.ts +6 -3
  34. package/src/execution/engine/tools/lead-service-types.ts +90 -30
  35. package/src/execution/engine/tools/platform/acquisition/types.ts +266 -260
  36. package/src/execution/engine/tools/registry.ts +5 -4
  37. package/src/execution/engine/tools/tool-maps.ts +43 -21
  38. package/src/execution/engine/workflow/types.ts +11 -0
  39. package/src/organization-model/contracts.ts +4 -4
  40. package/src/organization-model/domains/navigation.ts +62 -62
  41. package/src/organization-model/domains/sales.ts +272 -0
  42. package/src/organization-model/organization-graph.mdx +2 -2
  43. package/src/organization-model/published.ts +21 -21
  44. package/src/organization-model/resolve.ts +21 -8
  45. package/src/platform/constants/versions.ts +1 -1
  46. package/src/reference/_generated/contracts.md +2324 -0
  47. package/src/scaffold-registry/index.ts +10 -9
  48. package/src/scaffold-registry/schema.ts +68 -62
  49. package/src/supabase/database.types.ts +2958 -2884
  50. package/src/test-utils/rls/RLSTestContext.ts +585 -553
@@ -1,216 +1,217 @@
1
- import { describe, it, expect } from 'vitest'
2
- import { encryptCredential, decryptCredential } from '../server/encryption'
3
-
4
- // Note: SECRETS_ENCRYPTION_KEY is set in vitest.config.ts env section
5
- // The encryption module reads it at load time
6
-
7
- describe('Credential Encryption', () =>{
8
-
9
- describe('encryptCredential', () => {
10
- it('encrypts plaintext to base64-encoded JSON string', () => {
11
- const plaintext = 'my-secret-api-key'
12
- const encrypted = encryptCredential(plaintext)
13
-
14
- // Should be a valid JSON string
15
- expect(() => JSON.parse(encrypted)).not.toThrow()
16
-
17
- const parsed = JSON.parse(encrypted)
18
- expect(parsed).toHaveProperty('iv')
19
- expect(parsed).toHaveProperty('authTag')
20
- expect(parsed).toHaveProperty('data')
21
- })
22
-
23
- it('produces different ciphertext for same input (random IV)', () => {
24
- const plaintext = 'same-secret'
25
-
26
- const encrypted1 = encryptCredential(plaintext)
27
- const encrypted2 = encryptCredential(plaintext)
28
-
29
- // Different IVs mean different ciphertext
30
- expect(encrypted1).not.toBe(encrypted2)
31
-
32
- // But both decrypt to same plaintext
33
- expect(decryptCredential(encrypted1)).toBe(plaintext)
34
- expect(decryptCredential(encrypted2)).toBe(plaintext)
35
- })
36
-
37
- it('handles empty string', () => {
38
- const plaintext = ''
39
- const encrypted = encryptCredential(plaintext)
40
- const decrypted = decryptCredential(encrypted)
41
-
42
- expect(decrypted).toBe('')
43
- })
44
-
45
- it('handles long strings', () => {
46
- const plaintext = 'x'.repeat(10000)
47
- const encrypted = encryptCredential(plaintext)
48
- const decrypted = decryptCredential(encrypted)
49
-
50
- expect(decrypted).toBe(plaintext)
51
- })
52
-
53
- it('handles special characters and unicode', () => {
54
- const plaintext = 'Hello 世界! 🔐 Special chars: \n\t\r"\'\\`'
55
- const encrypted = encryptCredential(plaintext)
56
- const decrypted = decryptCredential(encrypted)
57
-
58
- expect(decrypted).toBe(plaintext)
59
- })
60
-
61
- it('validates key is configured at module load', () => {
62
- // We can't test missing key dynamically since MASTER_KEY is set at module load
63
- // Instead, verify the key is set and encryption works
64
- const encrypted = encryptCredential('test')
65
- expect(encrypted).toBeDefined()
66
- })
67
- })
68
-
69
- describe('decryptCredential', () => {
70
- it('decrypts ciphertext back to original plaintext', () => {
71
- const plaintext = 'my-secret-api-key'
72
- const encrypted = encryptCredential(plaintext)
73
- const decrypted = decryptCredential(encrypted)
74
-
75
- expect(decrypted).toBe(plaintext)
76
- })
77
-
78
- it('successfully decrypts with configured key', () => {
79
- const encrypted = encryptCredential('test')
80
- const decrypted = decryptCredential(encrypted)
81
-
82
- expect(decrypted).toBe('test')
83
- })
84
-
85
- it('throws error on malformed JSON', () => {
86
- expect(() => decryptCredential('not-json')).toThrow()
87
- })
88
-
89
- it('throws error on missing fields', () => {
90
- const invalidData = JSON.stringify({ iv: 'abc', authTag: 'def' }) // Missing 'data'
91
-
92
- expect(() => decryptCredential(invalidData)).toThrow()
93
- })
94
-
95
- it('throws error on tampered ciphertext', () => {
96
- const encrypted = encryptCredential('secret')
97
- const parsed = JSON.parse(encrypted)
98
-
99
- // Tamper with the data
100
- parsed.data = 'tampered-data'
101
- const tampered = JSON.stringify(parsed)
102
-
103
- expect(() => decryptCredential(tampered)).toThrow()
104
- })
105
-
106
- it('throws error on tampered auth tag', () => {
107
- const encrypted = encryptCredential('secret')
108
- const parsed = JSON.parse(encrypted)
109
-
110
- // Tamper with the auth tag
111
- parsed.authTag = 'AAAAAAAAAAAAAAAAAAAAAA=='
112
- const tampered = JSON.stringify(parsed)
113
-
114
- expect(() => decryptCredential(tampered)).toThrow()
115
- })
116
-
117
- it('detects tampering via auth tag (GCM mode)', () => {
118
- const encrypted = encryptCredential('secret')
119
- const parsed = JSON.parse(encrypted)
120
-
121
- // Tamper with just one byte of data
122
- const dataBuffer = Buffer.from(parsed.data, 'base64')
123
- dataBuffer[0] ^= 0x01 // Flip one bit
124
- parsed.data = dataBuffer.toString('base64')
125
-
126
- const tampered = JSON.stringify(parsed)
127
-
128
- // GCM should detect the tampering and throw
129
- expect(() => decryptCredential(tampered)).toThrow()
130
- })
131
-
132
- it('throws error on invalid base64 encoding', () => {
133
- const invalidData = JSON.stringify({
134
- iv: 'not-valid-base64!!!',
135
- authTag: 'AAAA',
136
- data: 'BBBB'
137
- })
138
-
139
- expect(() => decryptCredential(invalidData)).toThrow()
140
- })
141
- })
142
-
143
- describe('Round-trip encryption/decryption', () => {
144
- it('preserves API key format', () => {
145
- const apiKey = 'sk_test_1234567890abcdefghijklmnopqrstuvwxyz'
146
- const encrypted = encryptCredential(apiKey)
147
- const decrypted = decryptCredential(encrypted)
148
-
149
- expect(decrypted).toBe(apiKey)
150
- })
151
-
152
- it('preserves database connection strings', () => {
153
- const connString = 'postgresql://user:password@localhost:5432/database?sslmode=require'
154
- const encrypted = encryptCredential(connString)
155
- const decrypted = decryptCredential(encrypted)
156
-
157
- expect(decrypted).toBe(connString)
158
- })
159
-
160
- it('preserves JSON credentials', () => {
161
- const jsonCreds = JSON.stringify({
162
- type: 'service_account',
163
- project_id: 'my-project',
164
- private_key: '-----BEGIN PRIVATE KEY-----\nMIIE...\n-----END PRIVATE KEY-----\n'
165
- })
166
-
167
- const encrypted = encryptCredential(jsonCreds)
168
- const decrypted = decryptCredential(encrypted)
169
-
170
- expect(decrypted).toBe(jsonCreds)
171
- expect(JSON.parse(decrypted)).toEqual(JSON.parse(jsonCreds))
172
- })
173
- })
174
-
175
- describe('Security properties', () => {
176
- it('uses AES-256-GCM (authenticated encryption)', () => {
177
- const encrypted = encryptCredential('test')
178
- const parsed = JSON.parse(encrypted)
179
-
180
- // Auth tag should be present (GCM mode)
181
- expect(parsed.authTag).toBeDefined()
182
- expect(parsed.authTag.length).toBeGreaterThan(0)
183
- })
184
-
185
- it('uses random IV for each encryption', () => {
186
- const ivs = new Set()
187
-
188
- for (let i = 0; i < 100; i++) {
189
- const encrypted = encryptCredential('test')
190
- const parsed = JSON.parse(encrypted)
191
- ivs.add(parsed.iv)
192
- }
193
-
194
- // All IVs should be unique
195
- expect(ivs.size).toBe(100)
196
- })
197
-
198
- it('IV is 16 bytes (128 bits)', () => {
199
- const encrypted = encryptCredential('test')
200
- const parsed = JSON.parse(encrypted)
201
-
202
- // Base64-encoded 16 bytes = 24 characters
203
- const ivBuffer = Buffer.from(parsed.iv, 'base64')
204
- expect(ivBuffer.length).toBe(16)
205
- })
206
-
207
- it('auth tag is 16 bytes (128 bits)', () => {
208
- const encrypted = encryptCredential('test')
209
- const parsed = JSON.parse(encrypted)
210
-
211
- // Base64-encoded 16 bytes = 24 characters
212
- const authTagBuffer = Buffer.from(parsed.authTag, 'base64')
213
- expect(authTagBuffer.length).toBe(16)
214
- })
215
- })
216
- })
1
+ import crypto from 'crypto'
2
+ import { describe, it, expect, beforeAll } from 'vitest'
3
+ import { encryptCredential, decryptCredential, setKek, CURRENT_KEY_ID } from '../server/encryption'
4
+
5
+ beforeAll(() => {
6
+ setKek(CURRENT_KEY_ID, crypto.randomBytes(32))
7
+ })
8
+
9
+ describe('Credential Encryption', () => {
10
+ describe('encryptCredential', () => {
11
+ it('encrypts plaintext to base64-encoded JSON string', () => {
12
+ const plaintext = 'my-secret-api-key'
13
+ const encrypted = encryptCredential(plaintext)
14
+
15
+ // Should be a valid JSON string
16
+ expect(() => JSON.parse(encrypted)).not.toThrow()
17
+
18
+ const parsed = JSON.parse(encrypted)
19
+ expect(parsed).toHaveProperty('iv')
20
+ expect(parsed).toHaveProperty('authTag')
21
+ expect(parsed).toHaveProperty('data')
22
+ })
23
+
24
+ it('produces different ciphertext for same input (random IV)', () => {
25
+ const plaintext = 'same-secret'
26
+
27
+ const encrypted1 = encryptCredential(plaintext)
28
+ const encrypted2 = encryptCredential(plaintext)
29
+
30
+ // Different IVs mean different ciphertext
31
+ expect(encrypted1).not.toBe(encrypted2)
32
+
33
+ // But both decrypt to same plaintext
34
+ expect(decryptCredential(encrypted1)).toBe(plaintext)
35
+ expect(decryptCredential(encrypted2)).toBe(plaintext)
36
+ })
37
+
38
+ it('handles empty string', () => {
39
+ const plaintext = ''
40
+ const encrypted = encryptCredential(plaintext)
41
+ const decrypted = decryptCredential(encrypted)
42
+
43
+ expect(decrypted).toBe('')
44
+ })
45
+
46
+ it('handles long strings', () => {
47
+ const plaintext = 'x'.repeat(10000)
48
+ const encrypted = encryptCredential(plaintext)
49
+ const decrypted = decryptCredential(encrypted)
50
+
51
+ expect(decrypted).toBe(plaintext)
52
+ })
53
+
54
+ it('handles special characters and unicode', () => {
55
+ const plaintext = 'Hello 世界! 🔐 Special chars: \n\t\r"\'\\`'
56
+ const encrypted = encryptCredential(plaintext)
57
+ const decrypted = decryptCredential(encrypted)
58
+
59
+ expect(decrypted).toBe(plaintext)
60
+ })
61
+
62
+ it('validates key is configured at module load', () => {
63
+ // We can't test missing key dynamically since MASTER_KEY is set at module load
64
+ // Instead, verify the key is set and encryption works
65
+ const encrypted = encryptCredential('test')
66
+ expect(encrypted).toBeDefined()
67
+ })
68
+ })
69
+
70
+ describe('decryptCredential', () => {
71
+ it('decrypts ciphertext back to original plaintext', () => {
72
+ const plaintext = 'my-secret-api-key'
73
+ const encrypted = encryptCredential(plaintext)
74
+ const decrypted = decryptCredential(encrypted)
75
+
76
+ expect(decrypted).toBe(plaintext)
77
+ })
78
+
79
+ it('successfully decrypts with configured key', () => {
80
+ const encrypted = encryptCredential('test')
81
+ const decrypted = decryptCredential(encrypted)
82
+
83
+ expect(decrypted).toBe('test')
84
+ })
85
+
86
+ it('throws error on malformed JSON', () => {
87
+ expect(() => decryptCredential('not-json')).toThrow()
88
+ })
89
+
90
+ it('throws error on missing fields', () => {
91
+ const invalidData = JSON.stringify({ iv: 'abc', authTag: 'def' }) // Missing 'data'
92
+
93
+ expect(() => decryptCredential(invalidData)).toThrow()
94
+ })
95
+
96
+ it('throws error on tampered ciphertext', () => {
97
+ const encrypted = encryptCredential('secret')
98
+ const parsed = JSON.parse(encrypted)
99
+
100
+ // Tamper with the data
101
+ parsed.data = 'tampered-data'
102
+ const tampered = JSON.stringify(parsed)
103
+
104
+ expect(() => decryptCredential(tampered)).toThrow()
105
+ })
106
+
107
+ it('throws error on tampered auth tag', () => {
108
+ const encrypted = encryptCredential('secret')
109
+ const parsed = JSON.parse(encrypted)
110
+
111
+ // Tamper with the auth tag
112
+ parsed.authTag = 'AAAAAAAAAAAAAAAAAAAAAA=='
113
+ const tampered = JSON.stringify(parsed)
114
+
115
+ expect(() => decryptCredential(tampered)).toThrow()
116
+ })
117
+
118
+ it('detects tampering via auth tag (GCM mode)', () => {
119
+ const encrypted = encryptCredential('secret')
120
+ const parsed = JSON.parse(encrypted)
121
+
122
+ // Tamper with just one byte of data
123
+ const dataBuffer = Buffer.from(parsed.data, 'base64')
124
+ dataBuffer[0] ^= 0x01 // Flip one bit
125
+ parsed.data = dataBuffer.toString('base64')
126
+
127
+ const tampered = JSON.stringify(parsed)
128
+
129
+ // GCM should detect the tampering and throw
130
+ expect(() => decryptCredential(tampered)).toThrow()
131
+ })
132
+
133
+ it('throws error on invalid base64 encoding', () => {
134
+ const invalidData = JSON.stringify({
135
+ iv: 'not-valid-base64!!!',
136
+ authTag: 'AAAA',
137
+ data: 'BBBB'
138
+ })
139
+
140
+ expect(() => decryptCredential(invalidData)).toThrow()
141
+ })
142
+ })
143
+
144
+ describe('Round-trip encryption/decryption', () => {
145
+ it('preserves API key format', () => {
146
+ const apiKey = 'sk_test_1234567890abcdefghijklmnopqrstuvwxyz'
147
+ const encrypted = encryptCredential(apiKey)
148
+ const decrypted = decryptCredential(encrypted)
149
+
150
+ expect(decrypted).toBe(apiKey)
151
+ })
152
+
153
+ it('preserves database connection strings', () => {
154
+ const connString = 'postgresql://user:password@localhost:5432/database?sslmode=require'
155
+ const encrypted = encryptCredential(connString)
156
+ const decrypted = decryptCredential(encrypted)
157
+
158
+ expect(decrypted).toBe(connString)
159
+ })
160
+
161
+ it('preserves JSON credentials', () => {
162
+ const jsonCreds = JSON.stringify({
163
+ type: 'service_account',
164
+ project_id: 'my-project',
165
+ private_key: '-----BEGIN PRIVATE KEY-----\nMIIE...\n-----END PRIVATE KEY-----\n'
166
+ })
167
+
168
+ const encrypted = encryptCredential(jsonCreds)
169
+ const decrypted = decryptCredential(encrypted)
170
+
171
+ expect(decrypted).toBe(jsonCreds)
172
+ expect(JSON.parse(decrypted)).toEqual(JSON.parse(jsonCreds))
173
+ })
174
+ })
175
+
176
+ describe('Security properties', () => {
177
+ it('uses AES-256-GCM (authenticated encryption)', () => {
178
+ const encrypted = encryptCredential('test')
179
+ const parsed = JSON.parse(encrypted)
180
+
181
+ // Auth tag should be present (GCM mode)
182
+ expect(parsed.authTag).toBeDefined()
183
+ expect(parsed.authTag.length).toBeGreaterThan(0)
184
+ })
185
+
186
+ it('uses random IV for each encryption', () => {
187
+ const ivs = new Set()
188
+
189
+ for (let i = 0; i < 100; i++) {
190
+ const encrypted = encryptCredential('test')
191
+ const parsed = JSON.parse(encrypted)
192
+ ivs.add(parsed.iv)
193
+ }
194
+
195
+ // All IVs should be unique
196
+ expect(ivs.size).toBe(100)
197
+ })
198
+
199
+ it('IV is 16 bytes (128 bits)', () => {
200
+ const encrypted = encryptCredential('test')
201
+ const parsed = JSON.parse(encrypted)
202
+
203
+ // Base64-encoded 16 bytes = 24 characters
204
+ const ivBuffer = Buffer.from(parsed.iv, 'base64')
205
+ expect(ivBuffer.length).toBe(16)
206
+ })
207
+
208
+ it('auth tag is 16 bytes (128 bits)', () => {
209
+ const encrypted = encryptCredential('test')
210
+ const parsed = JSON.parse(encrypted)
211
+
212
+ // Base64-encoded 16 bytes = 24 characters
213
+ const authTagBuffer = Buffer.from(parsed.authTag, 'base64')
214
+ expect(authTagBuffer.length).toBe(16)
215
+ })
216
+ })
217
+ })
@@ -5,10 +5,10 @@ const ALGORITHM = 'aes-256-gcm'
5
5
  // keyId stamped on all newly encrypted ciphertexts.
6
6
  export const CURRENT_KEY_ID = 'platform-v1'
7
7
 
8
- // Implicit keyId for pre-Vault ciphertext rows that were encrypted before this
9
- // field existed. The kek-loader registers the legacy SECRETS_ENCRYPTION_KEY env
10
- // value under this id during the migration window so existing rows decrypt
11
- // until the re-encryption script (B4) restamps them with CURRENT_KEY_ID.
8
+ // Implicit keyId for pre-Vault ciphertext rows that lack a keyId field. All
9
+ // known rows were restamped with CURRENT_KEY_ID during the re-encryption
10
+ // migration; this constant remains only so any unexpected legacy blob produces
11
+ // a clear "KEK not loaded" error rather than a silent default-key decrypt.
12
12
  export const LEGACY_KEY_ID = 'platform-v0-legacy'
13
13
 
14
14
  interface EncryptedData {
@@ -32,21 +32,7 @@ export function clearKeks(): void {
32
32
  }
33
33
 
34
34
  function resolveKek(keyId: string): Buffer | undefined {
35
- const cached = kekMap.get(keyId)
36
- if (cached) return cached
37
-
38
- // Non-production fallback: bootstrap from SECRETS_ENCRYPTION_KEY so tests and
39
- // local dev keep working without an explicit setKek() boot step. Production
40
- // must register KEKs via the kek-loader; the env var is removed in Wave B5.
41
- if (process.env.NODE_ENV !== 'production' && process.env.SECRETS_ENCRYPTION_KEY) {
42
- const envKey = Buffer.from(process.env.SECRETS_ENCRYPTION_KEY, 'hex')
43
- if (envKey.length === 32) {
44
- kekMap.set(keyId, envKey)
45
- return envKey
46
- }
47
- }
48
-
49
- return undefined
35
+ return kekMap.get(keyId)
50
36
  }
51
37
 
52
38
  export function encryptCredential(plaintext: string): string {
@@ -1,18 +1,16 @@
1
1
  import { getSupabaseClient } from '../../../../supabase/server/client'
2
- import { setKek, CURRENT_KEY_ID, LEGACY_KEY_ID } from './encryption'
2
+ import { setKek, CURRENT_KEY_ID } from './encryption'
3
3
 
4
4
  let loaded = false
5
5
 
6
6
  /**
7
7
  * Loads the platform credential KEK from Supabase Vault and registers it under
8
- * `CURRENT_KEY_ID` ('platform-v1'). During the migration window, also registers
9
- * the legacy `SECRETS_ENCRYPTION_KEY` env var under `LEGACY_KEY_ID` so existing
10
- * ciphertext rows (no `keyId` field) can still be decrypted.
8
+ * `CURRENT_KEY_ID` ('platform-v1').
11
9
  *
12
10
  * Idempotent: subsequent calls are no-ops.
13
11
  *
14
12
  * Fails fast on missing / malformed Vault KEK so misconfigured deploys do not
15
- * silently fall through to env-only encryption.
13
+ * silently start without a usable encryption key.
16
14
  */
17
15
  export async function loadCredentialKEKs(): Promise<void> {
18
16
  if (loaded) return
@@ -35,13 +33,5 @@ export async function loadCredentialKEKs(): Promise<void> {
35
33
  }
36
34
  setKek(CURRENT_KEY_ID, vaultKek)
37
35
 
38
- const legacyHex = process.env.SECRETS_ENCRYPTION_KEY
39
- if (legacyHex) {
40
- const legacyKey = Buffer.from(legacyHex, 'hex')
41
- if (legacyKey.length === 32) {
42
- setKek(LEGACY_KEY_ID, legacyKey)
43
- }
44
- }
45
-
46
36
  loaded = true
47
37
  }
@@ -8,7 +8,7 @@
8
8
  *
9
9
  * The DB table `org_rol_permissions` mirrors this constant. Reconciliation
10
10
  * runs at API boot (insert-or-update only — never auto-delete; see the
11
- * deletion runbook in the auth-role-system-redesign doc).
11
+ * deletion runbook in the auth-role-system doc -- review/auth-role-system/).
12
12
  *
13
13
  * Adding a permission:
14
14
  * 1. Add an entry below.
@@ -29,7 +29,8 @@ export const PERMISSIONS = {
29
29
  SECRETS_MANAGE: 'secrets.manage',
30
30
  OPERATIONS_READ: 'operations.read',
31
31
  OPERATIONS_MANAGE: 'operations.manage',
32
- WORK_MANAGE: 'work.manage'
32
+ ACQUISITION_MANAGE: 'acquisition.manage',
33
+ PROJECTS_MANAGE: 'projects.manage'
33
34
  } as const
34
35
 
35
36
  export type PermissionKey = (typeof PERMISSIONS)[keyof typeof PERMISSIONS]
@@ -87,9 +88,15 @@ export const PERMISSION_CATALOG: readonly PermissionDescriptor[] = [
87
88
  isOrgGrantable: true
88
89
  },
89
90
  {
90
- key: 'work.manage',
91
- description: 'Create and edit business-domain records (acq_*, prj_*)',
92
- isOrgGrantable: true
91
+ key: 'acquisition.manage',
92
+ description:
93
+ 'Create, update, and delete acquisition records (acq_companies, acq_contacts, acq_deals, acq_lists*, acq_content*, acquisition storage files)',
94
+ isOrgGrantable: false
95
+ },
96
+ {
97
+ key: 'projects.manage',
98
+ description: 'Create, update, and delete project records (prj_projects, prj_milestones, prj_tasks, prj_notes)',
99
+ isOrgGrantable: false
93
100
  }
94
101
  ] as const
95
102