@capgo/capacitor-supabase 8.0.4

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,754 @@
1
+ import type { PluginListenerHandle } from '@capacitor/core';
2
+ /**
3
+ * Configuration options for initializing the Supabase client.
4
+ *
5
+ * @since 0.0.1
6
+ */
7
+ export interface SupabaseConfig {
8
+ /**
9
+ * The Supabase project URL.
10
+ *
11
+ * @since 0.0.1
12
+ * @example "https://xyzcompany.supabase.co"
13
+ */
14
+ supabaseUrl: string;
15
+ /**
16
+ * The Supabase anonymous/public key.
17
+ *
18
+ * @since 0.0.1
19
+ */
20
+ supabaseKey: string;
21
+ }
22
+ /**
23
+ * User object returned from authentication operations.
24
+ *
25
+ * @since 0.0.1
26
+ */
27
+ export interface User {
28
+ /**
29
+ * Unique identifier for the user.
30
+ *
31
+ * @since 0.0.1
32
+ */
33
+ id: string;
34
+ /**
35
+ * User's email address.
36
+ *
37
+ * @since 0.0.1
38
+ */
39
+ email?: string;
40
+ /**
41
+ * User's phone number.
42
+ *
43
+ * @since 0.0.1
44
+ */
45
+ phone?: string;
46
+ /**
47
+ * Timestamp when the user was created.
48
+ *
49
+ * @since 0.0.1
50
+ */
51
+ createdAt?: string;
52
+ /**
53
+ * Timestamp when the user last signed in.
54
+ *
55
+ * @since 0.0.1
56
+ */
57
+ lastSignInAt?: string;
58
+ /**
59
+ * User metadata (custom fields).
60
+ *
61
+ * @since 0.0.1
62
+ */
63
+ userMetadata?: Record<string, unknown>;
64
+ /**
65
+ * App metadata.
66
+ *
67
+ * @since 0.0.1
68
+ */
69
+ appMetadata?: Record<string, unknown>;
70
+ }
71
+ /**
72
+ * Session object containing authentication tokens.
73
+ *
74
+ * @since 0.0.1
75
+ */
76
+ export interface Session {
77
+ /**
78
+ * The JWT access token. Use this for authenticated API requests.
79
+ *
80
+ * @since 0.0.1
81
+ */
82
+ accessToken: string;
83
+ /**
84
+ * The refresh token for obtaining new access tokens.
85
+ *
86
+ * @since 0.0.1
87
+ */
88
+ refreshToken: string;
89
+ /**
90
+ * Token type (usually "bearer").
91
+ *
92
+ * @since 0.0.1
93
+ */
94
+ tokenType: string;
95
+ /**
96
+ * Number of seconds until the access token expires.
97
+ *
98
+ * @since 0.0.1
99
+ */
100
+ expiresIn: number;
101
+ /**
102
+ * Unix timestamp when the token expires.
103
+ *
104
+ * @since 0.0.1
105
+ */
106
+ expiresAt?: number;
107
+ /**
108
+ * The authenticated user.
109
+ *
110
+ * @since 0.0.1
111
+ */
112
+ user: User;
113
+ }
114
+ /**
115
+ * Result of authentication operations that return a session.
116
+ *
117
+ * @since 0.0.1
118
+ */
119
+ export interface AuthResult {
120
+ /**
121
+ * The session if authentication was successful.
122
+ *
123
+ * @since 0.0.1
124
+ */
125
+ session: Session | null;
126
+ /**
127
+ * The authenticated user if successful.
128
+ *
129
+ * @since 0.0.1
130
+ */
131
+ user: User | null;
132
+ }
133
+ /**
134
+ * Options for email/password sign-in.
135
+ *
136
+ * @since 0.0.1
137
+ */
138
+ export interface SignInWithPasswordOptions {
139
+ /**
140
+ * User's email address.
141
+ *
142
+ * @since 0.0.1
143
+ */
144
+ email: string;
145
+ /**
146
+ * User's password.
147
+ *
148
+ * @since 0.0.1
149
+ */
150
+ password: string;
151
+ }
152
+ /**
153
+ * Options for email/password sign-up.
154
+ *
155
+ * @since 0.0.1
156
+ */
157
+ export interface SignUpOptions {
158
+ /**
159
+ * User's email address.
160
+ *
161
+ * @since 0.0.1
162
+ */
163
+ email: string;
164
+ /**
165
+ * User's password.
166
+ *
167
+ * @since 0.0.1
168
+ */
169
+ password: string;
170
+ /**
171
+ * Optional user metadata to store with the user.
172
+ *
173
+ * @since 0.0.1
174
+ */
175
+ data?: Record<string, unknown>;
176
+ }
177
+ /**
178
+ * Options for OAuth sign-in.
179
+ *
180
+ * @since 0.0.1
181
+ */
182
+ export interface SignInWithOAuthOptions {
183
+ /**
184
+ * The OAuth provider to use.
185
+ *
186
+ * @since 0.0.1
187
+ */
188
+ provider: OAuthProvider;
189
+ /**
190
+ * URL to redirect to after authentication.
191
+ *
192
+ * @since 0.0.1
193
+ */
194
+ redirectTo?: string;
195
+ /**
196
+ * OAuth scopes to request.
197
+ *
198
+ * @since 0.0.1
199
+ */
200
+ scopes?: string;
201
+ }
202
+ /**
203
+ * Supported OAuth providers.
204
+ *
205
+ * @since 0.0.1
206
+ */
207
+ export type OAuthProvider = 'apple' | 'azure' | 'bitbucket' | 'discord' | 'facebook' | 'figma' | 'github' | 'gitlab' | 'google' | 'kakao' | 'keycloak' | 'linkedin' | 'linkedin_oidc' | 'notion' | 'slack' | 'slack_oidc' | 'spotify' | 'twitch' | 'twitter' | 'workos' | 'zoom';
208
+ /**
209
+ * Options for OTP sign-in.
210
+ *
211
+ * @since 0.0.1
212
+ */
213
+ export interface SignInWithOtpOptions {
214
+ /**
215
+ * User's email address (required if phone is not provided).
216
+ *
217
+ * @since 0.0.1
218
+ */
219
+ email?: string;
220
+ /**
221
+ * User's phone number (required if email is not provided).
222
+ *
223
+ * @since 0.0.1
224
+ */
225
+ phone?: string;
226
+ }
227
+ /**
228
+ * Options for verifying OTP.
229
+ *
230
+ * @since 0.0.1
231
+ */
232
+ export interface VerifyOtpOptions {
233
+ /**
234
+ * User's email address (required if phone is not provided).
235
+ *
236
+ * @since 0.0.1
237
+ */
238
+ email?: string;
239
+ /**
240
+ * User's phone number (required if email is not provided).
241
+ *
242
+ * @since 0.0.1
243
+ */
244
+ phone?: string;
245
+ /**
246
+ * The OTP token received via email/SMS.
247
+ *
248
+ * @since 0.0.1
249
+ */
250
+ token: string;
251
+ /**
252
+ * The type of OTP verification.
253
+ *
254
+ * @since 0.0.1
255
+ */
256
+ type: 'sms' | 'email' | 'magiclink' | 'signup' | 'recovery';
257
+ }
258
+ /**
259
+ * Options for setting a session manually.
260
+ *
261
+ * @since 0.0.1
262
+ */
263
+ export interface SetSessionOptions {
264
+ /**
265
+ * The access token.
266
+ *
267
+ * @since 0.0.1
268
+ */
269
+ accessToken: string;
270
+ /**
271
+ * The refresh token.
272
+ *
273
+ * @since 0.0.1
274
+ */
275
+ refreshToken: string;
276
+ }
277
+ /**
278
+ * Auth state change event types.
279
+ *
280
+ * @since 0.0.1
281
+ */
282
+ export type AuthChangeEvent = 'INITIAL_SESSION' | 'SIGNED_IN' | 'SIGNED_OUT' | 'TOKEN_REFRESHED' | 'USER_UPDATED' | 'PASSWORD_RECOVERY';
283
+ /**
284
+ * Auth state change callback data.
285
+ *
286
+ * @since 0.0.1
287
+ */
288
+ export interface AuthStateChange {
289
+ /**
290
+ * The type of auth event.
291
+ *
292
+ * @since 0.0.1
293
+ */
294
+ event: AuthChangeEvent;
295
+ /**
296
+ * The current session (null if signed out).
297
+ *
298
+ * @since 0.0.1
299
+ */
300
+ session: Session | null;
301
+ }
302
+ /**
303
+ * Options for database select queries.
304
+ *
305
+ * @since 0.0.1
306
+ */
307
+ export interface SelectOptions {
308
+ /**
309
+ * The table name to query.
310
+ *
311
+ * @since 0.0.1
312
+ */
313
+ table: string;
314
+ /**
315
+ * Columns to select (default: "*").
316
+ *
317
+ * @since 0.0.1
318
+ */
319
+ columns?: string;
320
+ /**
321
+ * Filter conditions as key-value pairs.
322
+ *
323
+ * @since 0.0.1
324
+ */
325
+ filter?: Record<string, unknown>;
326
+ /**
327
+ * Maximum number of rows to return.
328
+ *
329
+ * @since 0.0.1
330
+ */
331
+ limit?: number;
332
+ /**
333
+ * Number of rows to skip.
334
+ *
335
+ * @since 0.0.1
336
+ */
337
+ offset?: number;
338
+ /**
339
+ * Column to order by.
340
+ *
341
+ * @since 0.0.1
342
+ */
343
+ orderBy?: string;
344
+ /**
345
+ * Order direction.
346
+ *
347
+ * @since 0.0.1
348
+ */
349
+ ascending?: boolean;
350
+ /**
351
+ * Return a single row instead of an array.
352
+ *
353
+ * @since 0.0.1
354
+ */
355
+ single?: boolean;
356
+ }
357
+ /**
358
+ * Options for database insert queries.
359
+ *
360
+ * @since 0.0.1
361
+ */
362
+ export interface InsertOptions {
363
+ /**
364
+ * The table name to insert into.
365
+ *
366
+ * @since 0.0.1
367
+ */
368
+ table: string;
369
+ /**
370
+ * The data to insert (single object or array of objects).
371
+ *
372
+ * @since 0.0.1
373
+ */
374
+ values: Record<string, unknown> | Record<string, unknown>[];
375
+ }
376
+ /**
377
+ * Options for database update queries.
378
+ *
379
+ * @since 0.0.1
380
+ */
381
+ export interface UpdateOptions {
382
+ /**
383
+ * The table name to update.
384
+ *
385
+ * @since 0.0.1
386
+ */
387
+ table: string;
388
+ /**
389
+ * The data to update.
390
+ *
391
+ * @since 0.0.1
392
+ */
393
+ values: Record<string, unknown>;
394
+ /**
395
+ * Filter conditions to match rows to update.
396
+ *
397
+ * @since 0.0.1
398
+ */
399
+ filter: Record<string, unknown>;
400
+ }
401
+ /**
402
+ * Options for database delete queries.
403
+ *
404
+ * @since 0.0.1
405
+ */
406
+ export interface DeleteOptions {
407
+ /**
408
+ * The table name to delete from.
409
+ *
410
+ * @since 0.0.1
411
+ */
412
+ table: string;
413
+ /**
414
+ * Filter conditions to match rows to delete.
415
+ *
416
+ * @since 0.0.1
417
+ */
418
+ filter: Record<string, unknown>;
419
+ }
420
+ /**
421
+ * Result of database queries.
422
+ *
423
+ * @since 0.0.1
424
+ */
425
+ export interface QueryResult<T = unknown> {
426
+ /**
427
+ * The query result data.
428
+ *
429
+ * @since 0.0.1
430
+ */
431
+ data: T | null;
432
+ /**
433
+ * Error message if the query failed.
434
+ *
435
+ * @since 0.0.1
436
+ */
437
+ error: string | null;
438
+ /**
439
+ * Number of affected rows (for insert/update/delete).
440
+ *
441
+ * @since 0.0.1
442
+ */
443
+ count?: number;
444
+ }
445
+ /**
446
+ * Capacitor Supabase Plugin for native Supabase SDK integration.
447
+ *
448
+ * This plugin provides native iOS and Android Supabase SDK functionality
449
+ * with the ability to retrieve JWT tokens for use in JavaScript/web layers.
450
+ *
451
+ * @since 0.0.1
452
+ */
453
+ export interface CapacitorSupabasePlugin {
454
+ /**
455
+ * Initialize the Supabase client with your project credentials.
456
+ * Must be called before any other methods.
457
+ *
458
+ * @param options - Configuration options including URL and API key
459
+ * @returns Promise that resolves when initialization is complete
460
+ * @throws Error if initialization fails
461
+ * @since 0.0.1
462
+ * @example
463
+ * ```typescript
464
+ * await CapacitorSupabase.initialize({
465
+ * supabaseUrl: 'https://xyzcompany.supabase.co',
466
+ * supabaseKey: 'your-anon-key'
467
+ * });
468
+ * ```
469
+ */
470
+ initialize(options: SupabaseConfig): Promise<void>;
471
+ /**
472
+ * Sign in with email and password.
473
+ *
474
+ * @param options - Email and password credentials
475
+ * @returns Promise with session and user data
476
+ * @throws Error if sign-in fails
477
+ * @since 0.0.1
478
+ * @example
479
+ * ```typescript
480
+ * const { session, user } = await CapacitorSupabase.signInWithPassword({
481
+ * email: 'user@example.com',
482
+ * password: 'password123'
483
+ * });
484
+ * console.log('JWT:', session?.accessToken);
485
+ * ```
486
+ */
487
+ signInWithPassword(options: SignInWithPasswordOptions): Promise<AuthResult>;
488
+ /**
489
+ * Sign up a new user with email and password.
490
+ *
491
+ * @param options - Email, password, and optional user metadata
492
+ * @returns Promise with session and user data
493
+ * @throws Error if sign-up fails
494
+ * @since 0.0.1
495
+ * @example
496
+ * ```typescript
497
+ * const { session, user } = await CapacitorSupabase.signUp({
498
+ * email: 'newuser@example.com',
499
+ * password: 'password123',
500
+ * data: { name: 'John Doe' }
501
+ * });
502
+ * ```
503
+ */
504
+ signUp(options: SignUpOptions): Promise<AuthResult>;
505
+ /**
506
+ * Sign in with an OAuth provider.
507
+ * Opens the provider's authentication page.
508
+ *
509
+ * @param options - OAuth provider and optional redirect URL
510
+ * @returns Promise that resolves when OAuth flow is initiated
511
+ * @throws Error if OAuth sign-in fails
512
+ * @since 0.0.1
513
+ * @example
514
+ * ```typescript
515
+ * await CapacitorSupabase.signInWithOAuth({
516
+ * provider: 'google',
517
+ * redirectTo: 'myapp://callback'
518
+ * });
519
+ * ```
520
+ */
521
+ signInWithOAuth(options: SignInWithOAuthOptions): Promise<void>;
522
+ /**
523
+ * Sign in with OTP (One-Time Password) sent via email or SMS.
524
+ *
525
+ * @param options - Email or phone number to send OTP to
526
+ * @returns Promise that resolves when OTP is sent
527
+ * @throws Error if sending OTP fails
528
+ * @since 0.0.1
529
+ * @example
530
+ * ```typescript
531
+ * await CapacitorSupabase.signInWithOtp({
532
+ * email: 'user@example.com'
533
+ * });
534
+ * ```
535
+ */
536
+ signInWithOtp(options: SignInWithOtpOptions): Promise<void>;
537
+ /**
538
+ * Verify an OTP token.
539
+ *
540
+ * @param options - Email/phone, token, and verification type
541
+ * @returns Promise with session and user data
542
+ * @throws Error if verification fails
543
+ * @since 0.0.1
544
+ * @example
545
+ * ```typescript
546
+ * const { session, user } = await CapacitorSupabase.verifyOtp({
547
+ * email: 'user@example.com',
548
+ * token: '123456',
549
+ * type: 'email'
550
+ * });
551
+ * ```
552
+ */
553
+ verifyOtp(options: VerifyOtpOptions): Promise<AuthResult>;
554
+ /**
555
+ * Sign out the current user.
556
+ *
557
+ * @returns Promise that resolves when sign-out is complete
558
+ * @throws Error if sign-out fails
559
+ * @since 0.0.1
560
+ * @example
561
+ * ```typescript
562
+ * await CapacitorSupabase.signOut();
563
+ * ```
564
+ */
565
+ signOut(): Promise<void>;
566
+ /**
567
+ * Get the current session if one exists.
568
+ * Returns the session with JWT access token.
569
+ *
570
+ * @returns Promise with the current session or null
571
+ * @throws Error if retrieving session fails
572
+ * @since 0.0.1
573
+ * @example
574
+ * ```typescript
575
+ * const { session } = await CapacitorSupabase.getSession();
576
+ * if (session) {
577
+ * console.log('JWT:', session.accessToken);
578
+ * // Use this token with @supabase/supabase-js
579
+ * }
580
+ * ```
581
+ */
582
+ getSession(): Promise<{
583
+ session: Session | null;
584
+ }>;
585
+ /**
586
+ * Refresh the current session and get new tokens.
587
+ *
588
+ * @returns Promise with the refreshed session
589
+ * @throws Error if refresh fails or no session exists
590
+ * @since 0.0.1
591
+ * @example
592
+ * ```typescript
593
+ * const { session } = await CapacitorSupabase.refreshSession();
594
+ * console.log('New JWT:', session?.accessToken);
595
+ * ```
596
+ */
597
+ refreshSession(): Promise<{
598
+ session: Session | null;
599
+ }>;
600
+ /**
601
+ * Get the currently authenticated user.
602
+ *
603
+ * @returns Promise with the current user or null
604
+ * @throws Error if retrieving user fails
605
+ * @since 0.0.1
606
+ * @example
607
+ * ```typescript
608
+ * const { user } = await CapacitorSupabase.getUser();
609
+ * if (user) {
610
+ * console.log('User ID:', user.id);
611
+ * }
612
+ * ```
613
+ */
614
+ getUser(): Promise<{
615
+ user: User | null;
616
+ }>;
617
+ /**
618
+ * Set the session manually with access and refresh tokens.
619
+ * Useful for restoring a session or integrating with external auth.
620
+ *
621
+ * @param options - Access and refresh tokens
622
+ * @returns Promise with the restored session
623
+ * @throws Error if setting session fails
624
+ * @since 0.0.1
625
+ * @example
626
+ * ```typescript
627
+ * const { session } = await CapacitorSupabase.setSession({
628
+ * accessToken: 'eyJ...',
629
+ * refreshToken: 'abc123'
630
+ * });
631
+ * ```
632
+ */
633
+ setSession(options: SetSessionOptions): Promise<{
634
+ session: Session | null;
635
+ }>;
636
+ /**
637
+ * Listen to authentication state changes.
638
+ *
639
+ * @param eventName - Must be 'authStateChange'
640
+ * @param listenerFunc - Callback function for auth state changes
641
+ * @returns Promise with handle to remove the listener
642
+ * @since 0.0.1
643
+ * @example
644
+ * ```typescript
645
+ * const listener = await CapacitorSupabase.addListener(
646
+ * 'authStateChange',
647
+ * ({ event, session }) => {
648
+ * console.log('Auth event:', event);
649
+ * if (session) {
650
+ * console.log('JWT:', session.accessToken);
651
+ * }
652
+ * }
653
+ * );
654
+ *
655
+ * // Later, remove the listener
656
+ * listener.remove();
657
+ * ```
658
+ */
659
+ addListener(eventName: 'authStateChange', listenerFunc: (data: AuthStateChange) => void): Promise<PluginListenerHandle>;
660
+ /**
661
+ * Remove all listeners for auth state changes.
662
+ *
663
+ * @since 0.0.1
664
+ * @example
665
+ * ```typescript
666
+ * await CapacitorSupabase.removeAllListeners();
667
+ * ```
668
+ */
669
+ removeAllListeners(): Promise<void>;
670
+ /**
671
+ * Execute a SELECT query on a table.
672
+ *
673
+ * @param options - Query options including table, columns, filters
674
+ * @returns Promise with query results
675
+ * @throws Error if query fails
676
+ * @since 0.0.1
677
+ * @example
678
+ * ```typescript
679
+ * const { data, error } = await CapacitorSupabase.select({
680
+ * table: 'users',
681
+ * columns: 'id, name, email',
682
+ * filter: { active: true },
683
+ * limit: 10,
684
+ * orderBy: 'created_at',
685
+ * ascending: false
686
+ * });
687
+ * ```
688
+ */
689
+ select<T = unknown>(options: SelectOptions): Promise<QueryResult<T[]>>;
690
+ /**
691
+ * Insert data into a table.
692
+ *
693
+ * @param options - Table name and values to insert
694
+ * @returns Promise with inserted data
695
+ * @throws Error if insert fails
696
+ * @since 0.0.1
697
+ * @example
698
+ * ```typescript
699
+ * const { data, error } = await CapacitorSupabase.insert({
700
+ * table: 'posts',
701
+ * values: { title: 'Hello', content: 'World' }
702
+ * });
703
+ * ```
704
+ */
705
+ insert<T = unknown>(options: InsertOptions): Promise<QueryResult<T>>;
706
+ /**
707
+ * Update data in a table.
708
+ *
709
+ * @param options - Table name, values to update, and filter conditions
710
+ * @returns Promise with updated data
711
+ * @throws Error if update fails
712
+ * @since 0.0.1
713
+ * @example
714
+ * ```typescript
715
+ * const { data, error } = await CapacitorSupabase.update({
716
+ * table: 'posts',
717
+ * values: { title: 'Updated Title' },
718
+ * filter: { id: 1 }
719
+ * });
720
+ * ```
721
+ */
722
+ update<T = unknown>(options: UpdateOptions): Promise<QueryResult<T>>;
723
+ /**
724
+ * Delete data from a table.
725
+ *
726
+ * @param options - Table name and filter conditions
727
+ * @returns Promise with deleted data
728
+ * @throws Error if delete fails
729
+ * @since 0.0.1
730
+ * @example
731
+ * ```typescript
732
+ * const { data, error } = await CapacitorSupabase.delete({
733
+ * table: 'posts',
734
+ * filter: { id: 1 }
735
+ * });
736
+ * ```
737
+ */
738
+ delete<T = unknown>(options: DeleteOptions): Promise<QueryResult<T>>;
739
+ /**
740
+ * Get the native Capacitor plugin version.
741
+ *
742
+ * @returns Promise that resolves with the plugin version
743
+ * @throws Error if getting the version fails
744
+ * @since 0.0.1
745
+ * @example
746
+ * ```typescript
747
+ * const { version } = await CapacitorSupabase.getPluginVersion();
748
+ * console.log('Plugin version:', version);
749
+ * ```
750
+ */
751
+ getPluginVersion(): Promise<{
752
+ version: string;
753
+ }>;
754
+ }