@vaiftech/sdk-expo 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-2026 VAIF Technologies
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,238 @@
1
+ # @vaif/sdk-expo
2
+
3
+ React Native and Expo SDK for VAIF Studio - a Backend-as-a-Service platform.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @vaif/sdk-expo @vaif/client @react-native-async-storage/async-storage
9
+ # or
10
+ pnpm add @vaif/sdk-expo @vaif/client @react-native-async-storage/async-storage
11
+ # or
12
+ yarn add @vaif/sdk-expo @vaif/client @react-native-async-storage/async-storage
13
+ ```
14
+
15
+ ## Quick Start
16
+
17
+ ```tsx
18
+ import { VaifProvider } from '@vaif/sdk-expo';
19
+ import { createVaifClient } from '@vaif/client';
20
+ import AsyncStorage from '@react-native-async-storage/async-storage';
21
+
22
+ const client = createVaifClient({
23
+ baseUrl: 'https://api.myproject.vaif.io',
24
+ apiKey: 'vaif_pk_xxx',
25
+ });
26
+
27
+ export default function App() {
28
+ return (
29
+ <VaifProvider client={client} storage={AsyncStorage}>
30
+ <MainApp />
31
+ </VaifProvider>
32
+ );
33
+ }
34
+ ```
35
+
36
+ ## Features
37
+
38
+ ### Persistent Sessions
39
+
40
+ Sessions are automatically persisted using AsyncStorage, so users stay logged in:
41
+
42
+ ```tsx
43
+ import { useAuth } from '@vaif/sdk-expo';
44
+
45
+ function LoginScreen() {
46
+ const { user, isLoading, signIn } = useAuth();
47
+
48
+ // Session restored from AsyncStorage on app start
49
+ if (isLoading) return <ActivityIndicator />;
50
+ if (user) return <Redirect to="/home" />;
51
+
52
+ return (
53
+ <Button
54
+ title="Sign In"
55
+ onPress={() => signIn({ email, password })}
56
+ />
57
+ );
58
+ }
59
+ ```
60
+
61
+ ### Image Upload from Camera/Gallery
62
+
63
+ Upload images directly from Expo ImagePicker:
64
+
65
+ ```tsx
66
+ import { useUpload } from '@vaif/sdk-expo';
67
+ import * as ImagePicker from 'expo-image-picker';
68
+
69
+ function ImageUpload() {
70
+ const { uploadUri, isUploading, progress } = useUpload();
71
+
72
+ const pickAndUpload = async () => {
73
+ const result = await ImagePicker.launchImageLibraryAsync({
74
+ mediaTypes: ImagePicker.MediaTypeOptions.Images,
75
+ quality: 0.8,
76
+ });
77
+
78
+ if (!result.canceled) {
79
+ const { uri } = result.assets[0];
80
+ const uploaded = await uploadUri(uri, `photos/${Date.now()}.jpg`);
81
+ console.log('Uploaded:', uploaded?.url);
82
+ }
83
+ };
84
+
85
+ return (
86
+ <View>
87
+ <Button
88
+ title={isUploading ? `Uploading ${progress}%` : 'Select Image'}
89
+ onPress={pickAndUpload}
90
+ disabled={isUploading}
91
+ />
92
+ </View>
93
+ );
94
+ }
95
+ ```
96
+
97
+ ### Realtime Updates
98
+
99
+ ```tsx
100
+ import { useRealtime, useRealtimePresence } from '@vaif/sdk-expo';
101
+
102
+ function ChatRoom({ roomId }) {
103
+ // Listen for new messages
104
+ useRealtime('messages', {
105
+ filters: [{ field: 'room_id', operator: 'eq', value: roomId }],
106
+ onInsert: (message) => {
107
+ // New message received
108
+ },
109
+ });
110
+
111
+ // Track online users
112
+ const { users, track, leave } = useRealtimePresence(`room-${roomId}`);
113
+
114
+ useEffect(() => {
115
+ track({ status: 'online' });
116
+ return () => leave();
117
+ }, []);
118
+
119
+ return (
120
+ <View>
121
+ <Text>Online: {users.length}</Text>
122
+ </View>
123
+ );
124
+ }
125
+ ```
126
+
127
+ ## Hooks Reference
128
+
129
+ ### Authentication
130
+
131
+ ```tsx
132
+ import { useAuth, useUser, useSession } from '@vaif/sdk-expo';
133
+
134
+ // Full auth functionality
135
+ const {
136
+ user,
137
+ isLoading,
138
+ isAuthenticated,
139
+ signIn,
140
+ signUp,
141
+ signOut,
142
+ signInWithOAuth,
143
+ updateProfile,
144
+ changePassword,
145
+ } = useAuth();
146
+
147
+ // Just the user
148
+ const { user, isLoading } = useUser();
149
+
150
+ // Session management
151
+ const { session, refresh } = useSession();
152
+ ```
153
+
154
+ ### Data
155
+
156
+ ```tsx
157
+ import { useQuery, useMutation, useRealtime } from '@vaif/sdk-expo';
158
+
159
+ // Fetch data
160
+ const { data, isLoading, error, refetch } = useQuery<Post>('posts', {
161
+ filters: [{ field: 'published', operator: 'eq', value: true }],
162
+ orderBy: [{ field: 'createdAt', direction: 'desc' }],
163
+ });
164
+
165
+ // Mutations
166
+ const { create, update, remove, isLoading } = useMutation<Post>('posts');
167
+
168
+ // Realtime subscriptions
169
+ useRealtime<Post>('posts', {
170
+ onInsert: (post) => { /* new post */ },
171
+ onUpdate: (post) => { /* updated post */ },
172
+ onDelete: (post) => { /* deleted post */ },
173
+ });
174
+ ```
175
+
176
+ ### Storage
177
+
178
+ ```tsx
179
+ import { useUpload, useDownload, usePublicUrl } from '@vaif/sdk-expo';
180
+
181
+ // Upload files
182
+ const { upload, uploadUri, isUploading, progress } = useUpload();
183
+
184
+ // Download files
185
+ const { download, isDownloading } = useDownload();
186
+
187
+ // Get public URL
188
+ const url = usePublicUrl('avatars/user-123.jpg');
189
+ ```
190
+
191
+ ### Functions
192
+
193
+ ```tsx
194
+ import { useFunction } from '@vaif/sdk-expo';
195
+
196
+ const { invoke, isInvoking, result, error } = useFunction('process-image');
197
+
198
+ const handleProcess = async () => {
199
+ await invoke({ imageUrl: 'https://...' });
200
+ };
201
+ ```
202
+
203
+ ### Presence & Broadcast
204
+
205
+ ```tsx
206
+ import { useRealtimePresence, useRealtimeBroadcast } from '@vaif/sdk-expo';
207
+
208
+ // Presence tracking
209
+ const { users, track, leave } = useRealtimePresence('room-1');
210
+
211
+ // Broadcast messaging
212
+ const { send, lastMessage, subscribe } = useRealtimeBroadcast('room-1');
213
+ ```
214
+
215
+ ## TypeScript Support
216
+
217
+ All hooks support TypeScript generics:
218
+
219
+ ```tsx
220
+ interface User {
221
+ id: string;
222
+ email: string;
223
+ name: string;
224
+ }
225
+
226
+ const { data } = useQuery<User>('users');
227
+ // data is User[] | undefined
228
+ ```
229
+
230
+ ## Related Packages
231
+
232
+ - [@vaif/client](https://www.npmjs.com/package/@vaif/client) - Core client SDK
233
+ - [@vaif/react](https://www.npmjs.com/package/@vaif/react) - React (web) hooks
234
+ - [@vaif/cli](https://www.npmjs.com/package/@vaif/cli) - CLI tools
235
+
236
+ ## License
237
+
238
+ MIT