@fiction/sdk 1.0.17 → 1.0.19

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.
@@ -0,0 +1,92 @@
1
+ import { z } from 'zod'
2
+ import { MediaSchema } from '@/types/media'
3
+
4
+ // Core self schema - define manually for better type control (still using Drizzle as reference)
5
+ export const selfSchema = z.object({
6
+ selfId: z.string().optional(),
7
+ handle: z.string().optional(),
8
+ ownerId: z.string().optional(),
9
+ orgId: z.string().optional(),
10
+ name: z.string().optional(),
11
+ title: z.string().nullable().optional(),
12
+ summary: z.string().nullable().optional(),
13
+ entityType: z.string().optional(),
14
+
15
+ // Media foreign keys and joined objects
16
+ avatarId: z.string().nullable().optional(),
17
+ coverId: z.string().nullable().optional(),
18
+ avatar: MediaSchema.optional(), // Joined MediaObject for UI
19
+ cover: MediaSchema.optional(), // Joined MediaObject for UI
20
+ voiceRecordings: z.array(MediaSchema).optional(), // Joined voice media with context: 'voice'
21
+
22
+ // Contact and social media
23
+ email: z.string().nullable().optional(),
24
+ website: z.string().url().nullable().optional(),
25
+ accounts: z.record(z.string(), z.object({
26
+ handle: z.string().optional(),
27
+ url: z.string().optional(),
28
+ })).nullable().optional(), // Social media accounts: { linkedin?: { handle: string }, x?: { handle: string }, etc. }
29
+
30
+ // AI Configuration
31
+ basePrompt: z.string().nullable().optional(),
32
+ firstMessage: z.string().nullable().optional(),
33
+ personalityPrompt: z.string().nullable().optional(), // AI-generated personality with concise examples
34
+ useCustomPrompts: z.boolean().nullable().optional(), // Boolean flag for custom vs generated prompts
35
+ elevenlabsVoiceId: z.string().nullable().optional(),
36
+ elevenlabsAgentId: z.string().nullable().optional(),
37
+
38
+ // Personality fields
39
+ headline: z.string().nullable().optional(),
40
+ industry: z.string().nullable().optional(),
41
+ location: z.string().nullable().optional(),
42
+ influences: z.array(z.string()).nullable().optional(),
43
+ interests: z.array(z.string()).nullable().optional(),
44
+ personalDetails: z.string().nullable().optional(),
45
+ cloutScore: z.number().nullable().optional(),
46
+
47
+ // Demographics (optional)
48
+ gender: z.string().nullable().optional(),
49
+ birthdayAt: z.string().nullable().optional(), // ISO date string
50
+
51
+ // Business configuration
52
+ businessTemplate: z.string().nullable().optional(),
53
+
54
+ // JSONB fields
55
+ enrichment: z.record(z.string(), z.any()).nullable().optional(),
56
+ onboarding: z.record(z.string(), z.any()).nullable().optional(),
57
+
58
+ // Joined org data - inline type following YAGNI principle
59
+ org: z.object({
60
+ orgId: z.string(),
61
+ handle: z.string(),
62
+ name: z.string(),
63
+ headline: z.string().optional(),
64
+ summary: z.string().optional(),
65
+ status: z.string(),
66
+ }).optional(),
67
+
68
+ // Meta
69
+ visibility: z.enum(['private', 'org', 'public']).optional(),
70
+ status: z.string().optional(),
71
+ createdAt: z.string().optional(), // ISO string for JSON compatibility
72
+ updatedAt: z.string().optional(), // ISO string for JSON compatibility
73
+ })
74
+
75
+ export const EnrichedSelfSchema = selfSchema.extend({
76
+ avatar: MediaSchema.optional(),
77
+ cover: MediaSchema.optional(),
78
+ voiceRecordings: z.array(MediaSchema).optional(),
79
+ isPrimary: z.boolean().optional(), // For selves within org context
80
+ })
81
+
82
+ // Type exports - all derived from Drizzle schema
83
+ export type Self = z.infer<typeof EnrichedSelfSchema>
84
+
85
+ // Create/Update types using the same flexible Self type
86
+ export type CreateSelf = Self
87
+ export type UpdateSelf = Self
88
+
89
+ // AiEnhancement type now imported from onboard/generation.ts
90
+
91
+ // Re-export Drizzle types for database operations
92
+ export type { Self as DrizzleSelf, SelfInsert as DrizzleSelfInsert } from '@/modules/db/tables/schema/selves'
@@ -0,0 +1,139 @@
1
+ import { z } from 'zod'
2
+ import { selfSchema } from '@/modules/self/schema'
3
+ import { MediaSchema } from '@/types/media'
4
+
5
+ export const userSchema = z.object({
6
+ userId: z.string(),
7
+ email: z.string().optional(),
8
+ handle: z.string().optional(),
9
+ fullName: z.string().optional(),
10
+ emailVerified: z.boolean().optional(),
11
+ hashedPassword: z.string().optional(),
12
+ primarySelfId: z.string().optional(),
13
+ onboarding: z.any().optional(),
14
+ recentSelfIds: z.array(z.string()).optional(),
15
+ status: z.string().optional(),
16
+ lastSeenAt: z.string().optional(),
17
+ createdAt: z.string().optional(),
18
+ updatedAt: z.string().optional(),
19
+ onboarded: z.boolean().optional(),
20
+ })
21
+
22
+ export const updateUserSchema = z.object({
23
+ name: z.string().min(1).max(100).optional(),
24
+ primarySelfId: z.string().optional(),
25
+ onboarding: z.any().optional(),
26
+ }).partial()
27
+
28
+ export const emailSchema = z.object({
29
+ email: z.string(),
30
+ })
31
+
32
+ export const loginSchema = z.object({
33
+ email: z.string(),
34
+ password: z.string().min(8, 'Password must be at least 8 characters'),
35
+ })
36
+
37
+ export const registerSchema = z.object({
38
+ email: z.string(),
39
+ password: z.string().min(8, 'Password must be at least 8 characters'),
40
+ fullName: z.string().min(1, 'Name is required'),
41
+ })
42
+
43
+ export const verifyCodeSchema = z.object({
44
+ email: z.string(),
45
+ code: z.string().min(6, 'Verification code is required'),
46
+ })
47
+
48
+ export const resetPasswordSchema = z.object({
49
+ email: z.string(),
50
+ code: z.string().min(6, 'Verification code is required'),
51
+ newPassword: z.string().min(8, 'New password must be at least 8 characters'),
52
+ })
53
+
54
+ export const changeEmailSchema = z.object({
55
+ newEmail: z.string(),
56
+ })
57
+
58
+ export const changePasswordSchema = z.object({
59
+ newPassword: z.string().min(8, 'New password must be at least 8 characters'),
60
+ })
61
+
62
+ export const googleAuthSchema = z.object({
63
+ credential: z.string().optional(),
64
+ code: z.string().optional(),
65
+ createOnEmpty: z.boolean().optional(),
66
+ }).refine((data) => data.credential || data.code, {
67
+ message: 'Either credential or code must be provided',
68
+ })
69
+
70
+ export const orgSchema = z.object({
71
+ orgId: z.string().optional(),
72
+ handle: z.string().optional(),
73
+ name: z.string().optional(),
74
+ email: z.string().optional(),
75
+ website: z.string().url().nullable().optional(),
76
+ summary: z.string().optional(),
77
+ avatarId: z.string().optional(),
78
+ avatar: MediaSchema.optional(),
79
+ coverId: z.string().optional(),
80
+ cover: MediaSchema.optional(),
81
+ accounts: z.record(z.string(), z.object({
82
+ handle: z.string().optional(),
83
+ url: z.string().optional(),
84
+ })).nullable().optional(),
85
+ ownerId: z.string().optional(),
86
+ billingStatus: z.string().optional(),
87
+ isPersonal: z.boolean().optional(),
88
+ stripeCustomerIdTest: z.string().optional(),
89
+ stripeCustomerIdLive: z.string().optional(),
90
+ subscriptionStatus: z.string().optional(),
91
+ planId: z.string().optional(),
92
+ maxSelves: z.number().optional(),
93
+ maxUsers: z.number().optional(),
94
+ onboarding: z.any().optional(),
95
+ status: z.string().optional(),
96
+ createdAt: z.string().optional(),
97
+ updatedAt: z.string().optional(),
98
+ })
99
+
100
+ export type User = z.infer<typeof userSchema>
101
+ export type UpdateUser = z.infer<typeof updateUserSchema>
102
+ export type Org = z.infer<typeof orgSchema>
103
+
104
+ export type { User as DrizzleUser, UserInsert as DrizzleUserInsert } from '@/modules/db/tables/schema/users'
105
+
106
+ export type AuthMode = 'start' | 'pass' | 'verify' | 'set-password' | 'forgot' | 'success'
107
+
108
+ export const orgInfoSchema = z.object({
109
+ membershipId: z.string(),
110
+ orgId: z.string(),
111
+ name: z.string(),
112
+ handle: z.string(),
113
+ avatarId: z.string().optional(),
114
+ avatar: MediaSchema.optional(),
115
+ coverId: z.string().optional(),
116
+ cover: MediaSchema.optional(),
117
+ role: z.enum(['owner', 'admin', 'member', 'observer']),
118
+ joinedAt: z.string(),
119
+ })
120
+
121
+ export const enrichedUserSchema = userSchema.extend({
122
+ orgs: z.array(orgInfoSchema).optional(),
123
+ memberships: z.array(orgInfoSchema).optional(),
124
+ selves: z.array(selfSchema).optional(),
125
+ })
126
+
127
+ export type OrgInfo = z.infer<typeof orgInfoSchema>
128
+ export type MembershipInfo = z.infer<typeof orgInfoSchema> // Alias for OrgInfo
129
+ export type EnrichedUser = z.infer<typeof enrichedUserSchema>
130
+
131
+ export type ApiResponse<T = any> = {
132
+ ok: true
133
+ data: T
134
+ user?: EnrichedUser
135
+ token?: string
136
+ } | {
137
+ ok: false
138
+ error: string
139
+ }