@elevasis/core 0.11.2 → 0.13.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 +2 -1
  2. package/dist/index.js +8 -1
  3. package/dist/organization-model/index.d.ts +2 -1
  4. package/dist/organization-model/index.js +8 -1
  5. package/dist/test-utils/index.d.ts +27 -15
  6. package/dist/test-utils/index.js +25 -0
  7. package/package.json +1 -1
  8. package/src/_gen/__tests__/__snapshots__/contracts.md.snap +27 -270
  9. package/src/auth/multi-tenancy/credentials/__tests__/encryption.test.ts +217 -216
  10. package/src/auth/multi-tenancy/credentials/server/encryption.ts +69 -39
  11. package/src/auth/multi-tenancy/credentials/server/kek-loader.ts +37 -0
  12. package/src/auth/multi-tenancy/index.ts +3 -0
  13. package/src/auth/multi-tenancy/invitations/api-schemas.ts +104 -107
  14. package/src/auth/multi-tenancy/memberships/api-schemas.ts +6 -5
  15. package/src/auth/multi-tenancy/memberships/membership.ts +130 -138
  16. package/src/auth/multi-tenancy/permissions.ts +12 -5
  17. package/src/auth/multi-tenancy/role-management/api-schemas.ts +78 -0
  18. package/src/auth/multi-tenancy/role-management/index.ts +16 -0
  19. package/src/business/acquisition/activity-events.ts +142 -0
  20. package/src/business/acquisition/api-schemas.ts +694 -689
  21. package/src/business/acquisition/derive-actions.ts +90 -0
  22. package/src/business/acquisition/index.ts +111 -109
  23. package/src/execution/engine/index.ts +434 -434
  24. package/src/execution/engine/tools/integration/server/adapters/apify/__tests__/apify-run-actor.integration.test.ts +298 -293
  25. package/src/execution/engine/tools/integration/server/adapters/attio/__tests__/attio-crud.integration.test.ts +0 -1
  26. package/src/execution/engine/tools/integration/service.test.ts +214 -0
  27. package/src/execution/engine/tools/integration/service.ts +169 -161
  28. package/src/execution/engine/tools/lead-service-types.ts +882 -879
  29. package/src/execution/engine/tools/registry.ts +699 -700
  30. package/src/execution/engine/tools/tool-maps.ts +777 -780
  31. package/src/integrations/credentials/__tests__/api-schemas.test.ts +420 -496
  32. package/src/integrations/credentials/api-schemas.ts +127 -143
  33. package/src/integrations/webhook-endpoints/__tests__/api-schemas.test.ts +327 -318
  34. package/src/integrations/webhook-endpoints/api-schemas.ts +103 -102
  35. package/src/integrations/webhook-endpoints/types.ts +58 -51
  36. package/src/operations/activities/api-schemas.ts +80 -79
  37. package/src/operations/activities/types.ts +64 -63
  38. package/src/organization-model/contracts.ts +1 -0
  39. package/src/organization-model/defaults.ts +6 -0
  40. package/src/organization-model/domains/navigation.ts +37 -23
  41. package/src/organization-model/organization-graph.mdx +2 -2
  42. package/src/organization-model/published.ts +2 -1
  43. package/src/platform/constants/versions.ts +1 -1
  44. package/src/reference/_generated/contracts.md +27 -270
  45. package/src/scaffold-registry/__tests__/index.test.ts +72 -7
  46. package/src/scaffold-registry/index.ts +163 -29
  47. package/src/scaffold-registry/schema.ts +68 -62
  48. package/src/server.ts +281 -272
  49. package/src/supabase/database.types.ts +16 -10
  50. package/src/test-utils/rls/RLSTestContext.ts +585 -553
@@ -1,143 +1,127 @@
1
- import { z } from 'zod'
2
- import { UuidSchema, CredentialNameSchema } from '../../platform/utils/validation'
3
-
4
- /**
5
- * Credential API Validation Schemas
6
- *
7
- * Separate from credential configuration schemas (schemas.ts).
8
- * - schemas.ts: Credential field definitions and type registry
9
- * - api-schemas.ts: HTTP request/response validation
10
- *
11
- * Design: Input Validation Standardization
12
- * @see apps/docs/content/docs/in-progress/active-development/security/active/credentials-integrations-validation-implementation.mdx
13
- */
14
-
15
- /**
16
- * Credential type validation
17
- * These are the actual `type` values stored in the database:
18
- * - 'oauth': All OAuth providers (notion, google-sheets) store this type
19
- * - 'api-key': Generic single-field API key credentials
20
- * - 'webhook-secret': Webhook signing secrets for signature validation
21
- *
22
- * Note: Provider-specific identifiers (notion, google-sheets) are CREDENTIAL_SCHEMAS
23
- * keys used for UI lookup, NOT stored type values. OAuth credentials store type='oauth'.
24
- */
25
- export const CredentialTypeSchema = z.enum(['oauth', 'api-key', 'webhook-secret', 'api-key-secret'])
26
-
27
- /**
28
- * Credential value validation
29
- * - Must be a non-empty object
30
- * - Keys are strings, values can be any JSON type
31
- * - Max 50 keys (prevents DoS)
32
- * - Individual string values max 10KB (prevents DoS)
33
- *
34
- * SECURITY:
35
- * - Prevents DoS via massive credential payloads
36
- * - Enforces reasonable limits for credential storage
37
- */
38
- const CredentialValueSchema = z
39
- .record(z.string(), z.unknown())
40
- .refine((val) => Object.keys(val).length > 0, { message: 'Credential value must not be empty' })
41
- .refine((val) => Object.keys(val).length <= 50, { message: 'Credential value has too many keys (max 50)' })
42
- .refine(
43
- (val) => {
44
- // Check individual string values for size
45
- for (const v of Object.values(val)) {
46
- if (typeof v === 'string' && v.length > 10240) {
47
- return false
48
- }
49
- }
50
- return true
51
- },
52
- { message: 'Individual credential values too large (max 10KB per string)' }
53
- )
54
-
55
- /**
56
- * POST /api/credentials - Create credential
57
- */
58
- export const CreateCredentialRequestSchema = z
59
- .object({
60
- name: CredentialNameSchema,
61
- type: CredentialTypeSchema,
62
- value: CredentialValueSchema,
63
- provider: z.string().optional() // OAuth provider ID ('dropbox', 'notion', 'google-sheets')
64
- })
65
- .strict() // Reject unknown fields (prevents mass assignment)
66
-
67
- /**
68
- * Response for credential creation
69
- */
70
- export const CreateCredentialResponseSchema = z.object({
71
- id: UuidSchema,
72
- name: z.string()
73
- })
74
-
75
- /**
76
- * GET /api/credentials - List credentials
77
- */
78
- export const ListCredentialsResponseSchema = z.object({
79
- credentials: z.array(
80
- z.object({
81
- id: UuidSchema,
82
- name: z.string(),
83
- type: z.string(),
84
- provider: z.string().nullable(), // OAuth provider or null for non-OAuth
85
- createdAt: z.string().datetime()
86
- })
87
- )
88
- })
89
-
90
- /** API response type for a single credential list item */
91
- export type CredentialListItem = z.infer<typeof ListCredentialsResponseSchema>['credentials'][number]
92
-
93
- /**
94
- * PATCH /api/credentials/:credentialId - Update credential
95
- */
96
- export const UpdateCredentialParamsSchema = z.object({
97
- credentialId: UuidSchema
98
- })
99
-
100
- export const UpdateCredentialRequestSchema = z
101
- .object({
102
- value: CredentialValueSchema.optional(),
103
- name: CredentialNameSchema.optional()
104
- })
105
- .strict()
106
- .refine((data) => data.value !== undefined || data.name !== undefined, {
107
- message: 'At least one field (value or name) must be provided'
108
- })
109
-
110
- /**
111
- * DELETE /api/credentials/:credentialId - Delete credential
112
- */
113
- export const DeleteCredentialParamsSchema = z.object({
114
- credentialId: UuidSchema
115
- })
116
-
117
- /**
118
- * GET /api/credentials/:credentialName/decrypt - CRITICAL ENDPOINT
119
- * Decrypt credential value for agent/tool use
120
- *
121
- * SECURITY: credentialName validated with strict regex to prevent path traversal
122
- */
123
- export const DecryptCredentialParamsSchema = z.object({
124
- credentialName: CredentialNameSchema
125
- })
126
-
127
- export const DecryptCredentialResponseSchema = z.object({
128
- value: z.record(z.string(), z.unknown())
129
- })
130
-
131
- /**
132
- * Export all schemas for use in routes
133
- */
134
- export const CredentialSchemas = {
135
- CreateRequest: CreateCredentialRequestSchema,
136
- CreateResponse: CreateCredentialResponseSchema,
137
- ListResponse: ListCredentialsResponseSchema,
138
- UpdateParams: UpdateCredentialParamsSchema,
139
- UpdateRequest: UpdateCredentialRequestSchema,
140
- DeleteParams: DeleteCredentialParamsSchema,
141
- DecryptParams: DecryptCredentialParamsSchema,
142
- DecryptResponse: DecryptCredentialResponseSchema
143
- }
1
+ import { z } from 'zod'
2
+ import { UuidSchema, CredentialNameSchema } from '../../platform/utils/validation'
3
+
4
+ /**
5
+ * Credential API Validation Schemas
6
+ *
7
+ * Separate from credential configuration schemas (schemas.ts).
8
+ * - schemas.ts: Credential field definitions and type registry
9
+ * - api-schemas.ts: HTTP request/response validation
10
+ *
11
+ * Design: Input Validation Standardization
12
+ * @see apps/docs/content/docs/in-progress/active-development/security/active/credentials-integrations-validation-implementation.mdx
13
+ */
14
+
15
+ /**
16
+ * Credential type validation
17
+ * These are the actual `type` values stored in the database:
18
+ * - 'oauth': All OAuth providers (notion, google-sheets) store this type
19
+ * - 'api-key': Generic single-field API key credentials
20
+ * - 'webhook-secret': Webhook signing secrets for signature validation
21
+ *
22
+ * Note: Provider-specific identifiers (notion, google-sheets) are CREDENTIAL_SCHEMAS
23
+ * keys used for UI lookup, NOT stored type values. OAuth credentials store type='oauth'.
24
+ */
25
+ export const CredentialTypeSchema = z.enum(['oauth', 'api-key', 'webhook-secret', 'api-key-secret'])
26
+
27
+ /**
28
+ * Credential value validation
29
+ * - Must be a non-empty object
30
+ * - Keys are strings, values can be any JSON type
31
+ * - Max 50 keys (prevents DoS)
32
+ * - Individual string values max 10KB (prevents DoS)
33
+ *
34
+ * SECURITY:
35
+ * - Prevents DoS via massive credential payloads
36
+ * - Enforces reasonable limits for credential storage
37
+ */
38
+ const CredentialValueSchema = z
39
+ .record(z.string(), z.unknown())
40
+ .refine((val) => Object.keys(val).length > 0, { message: 'Credential value must not be empty' })
41
+ .refine((val) => Object.keys(val).length <= 50, { message: 'Credential value has too many keys (max 50)' })
42
+ .refine(
43
+ (val) => {
44
+ // Check individual string values for size
45
+ for (const v of Object.values(val)) {
46
+ if (typeof v === 'string' && v.length > 10240) {
47
+ return false
48
+ }
49
+ }
50
+ return true
51
+ },
52
+ { message: 'Individual credential values too large (max 10KB per string)' }
53
+ )
54
+
55
+ /**
56
+ * POST /api/credentials - Create credential
57
+ */
58
+ export const CreateCredentialRequestSchema = z
59
+ .object({
60
+ name: CredentialNameSchema,
61
+ type: CredentialTypeSchema,
62
+ value: CredentialValueSchema,
63
+ provider: z.string().optional() // OAuth provider ID ('dropbox', 'notion', 'google-sheets')
64
+ })
65
+ .strict() // Reject unknown fields (prevents mass assignment)
66
+
67
+ /**
68
+ * Response for credential creation
69
+ */
70
+ export const CreateCredentialResponseSchema = z.object({
71
+ id: UuidSchema,
72
+ name: z.string()
73
+ })
74
+
75
+ /**
76
+ * GET /api/credentials - List credentials
77
+ */
78
+ export const ListCredentialsResponseSchema = z.object({
79
+ credentials: z.array(
80
+ z.object({
81
+ id: UuidSchema,
82
+ name: z.string(),
83
+ type: z.string(),
84
+ provider: z.string().nullable(), // OAuth provider or null for non-OAuth
85
+ createdAt: z.string().datetime()
86
+ })
87
+ )
88
+ })
89
+
90
+ /** API response type for a single credential list item */
91
+ export type CredentialListItem = z.infer<typeof ListCredentialsResponseSchema>['credentials'][number]
92
+
93
+ /**
94
+ * PATCH /api/credentials/:credentialId - Update credential
95
+ */
96
+ export const UpdateCredentialParamsSchema = z.object({
97
+ credentialId: UuidSchema
98
+ })
99
+
100
+ export const UpdateCredentialRequestSchema = z
101
+ .object({
102
+ value: CredentialValueSchema.optional(),
103
+ name: CredentialNameSchema.optional()
104
+ })
105
+ .strict()
106
+ .refine((data) => data.value !== undefined || data.name !== undefined, {
107
+ message: 'At least one field (value or name) must be provided'
108
+ })
109
+
110
+ /**
111
+ * DELETE /api/credentials/:credentialId - Delete credential
112
+ */
113
+ export const DeleteCredentialParamsSchema = z.object({
114
+ credentialId: UuidSchema
115
+ })
116
+
117
+ /**
118
+ * Export all schemas for use in routes
119
+ */
120
+ export const CredentialSchemas = {
121
+ CreateRequest: CreateCredentialRequestSchema,
122
+ CreateResponse: CreateCredentialResponseSchema,
123
+ ListResponse: ListCredentialsResponseSchema,
124
+ UpdateParams: UpdateCredentialParamsSchema,
125
+ UpdateRequest: UpdateCredentialRequestSchema,
126
+ DeleteParams: DeleteCredentialParamsSchema
127
+ }