vasabase-js 0.0.1

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 (3) hide show
  1. package/dist/index.d.ts +357 -0
  2. package/dist/index.js +1089 -0
  3. package/package.json +21 -0
@@ -0,0 +1,357 @@
1
+ export declare function createClient(url: string, key: string, options?: {
2
+ projectRef?: string;
3
+ }): VasabaseClient;
4
+ export declare class PostgrestError extends Error {
5
+ code?: number;
6
+ details?: string;
7
+ constructor(message: string, code?: number, details?: string);
8
+ }
9
+ export declare class AuthError extends Error {
10
+ code?: number;
11
+ details?: string;
12
+ constructor(message: string, code?: number, details?: string);
13
+ }
14
+ export declare class FunctionsError extends Error {
15
+ code?: number;
16
+ constructor(message: string, code?: number);
17
+ }
18
+ export interface User {
19
+ id: string;
20
+ email: string;
21
+ user_metadata?: Record<string, any>;
22
+ }
23
+ export interface Session {
24
+ access_token: string;
25
+ refresh_token?: string;
26
+ expires_in: number;
27
+ user: User;
28
+ }
29
+ export interface Factor {
30
+ id: string;
31
+ friendly_name?: string;
32
+ factor_type: 'totp' | 'webauthn';
33
+ status: 'verified' | 'unverified';
34
+ created_at: string;
35
+ updated_at: string;
36
+ }
37
+ export type AuthChangeEventType = 'SIGNED_IN' | 'SIGNED_OUT' | 'TOKEN_REFRESHED' | 'USER_UPDATED' | 'PASSWORD_RECOVERY';
38
+ export interface PostgresCDCConfig {
39
+ event: 'INSERT' | 'UPDATE' | 'DELETE' | '*';
40
+ schema?: string;
41
+ filter?: string;
42
+ }
43
+ export interface RealtimePayload {
44
+ event: string;
45
+ schema: string;
46
+ table: string;
47
+ new: Record<string, any>;
48
+ old: Record<string, any>;
49
+ }
50
+ export declare class VasabaseClient {
51
+ auth: AuthClient;
52
+ rest: PostgrestClient;
53
+ storage: StorageClient;
54
+ realtime: RealtimeClient;
55
+ functions: FunctionsClient;
56
+ private url;
57
+ private key;
58
+ private projectRef;
59
+ constructor(url: string, key: string, options?: {
60
+ projectRef?: string;
61
+ });
62
+ from(table: string): PostgrestQueryBuilder;
63
+ }
64
+ declare class PostgrestClient {
65
+ private url;
66
+ private key;
67
+ private projectRef;
68
+ private getAuthHeaders;
69
+ constructor(url: string, key: string, projectRef: string, getAuthHeaders: () => Record<string, string>);
70
+ from(table: string): PostgrestQueryBuilder;
71
+ }
72
+ declare class PostgrestQueryBuilder {
73
+ private url;
74
+ private key;
75
+ private projectRef;
76
+ private getAuthHeaders;
77
+ private table;
78
+ private method;
79
+ private query;
80
+ private body;
81
+ private headers;
82
+ private _notPrefix;
83
+ constructor(url: string, key: string, projectRef: string, getAuthHeaders: () => Record<string, string>, table: string, method?: string, query?: Record<string, string>, body?: any, headers?: Record<string, string>, notPrefix?: string);
84
+ private clone;
85
+ select(columns?: string): PostgrestQueryBuilder;
86
+ insert(data: any | any[]): PostgrestQueryBuilder;
87
+ upsert(data: any | any[], onConflict?: string): PostgrestQueryBuilder;
88
+ update(data: any): PostgrestQueryBuilder;
89
+ delete(): PostgrestQueryBuilder;
90
+ eq(column: string, value: any): PostgrestQueryBuilder;
91
+ neq(column: string, value: any): PostgrestQueryBuilder;
92
+ gt(column: string, value: any): PostgrestQueryBuilder;
93
+ gte(column: string, value: any): PostgrestQueryBuilder;
94
+ lt(column: string, value: any): PostgrestQueryBuilder;
95
+ lte(column: string, value: any): PostgrestQueryBuilder;
96
+ like(column: string, pattern: string): PostgrestQueryBuilder;
97
+ ilike(column: string, pattern: string): PostgrestQueryBuilder;
98
+ is_(column: string, value: boolean | null): PostgrestQueryBuilder;
99
+ isNull(column: string): PostgrestQueryBuilder;
100
+ in_(column: string, values: any[]): PostgrestQueryBuilder;
101
+ contains(column: string, value: any): PostgrestQueryBuilder;
102
+ containedBy(column: string, value: any): PostgrestQueryBuilder;
103
+ match(column: string, query: Record<string, any>): PostgrestQueryBuilder;
104
+ imatch(column: string, query: Record<string, any>): PostgrestQueryBuilder;
105
+ or(filter: string): PostgrestQueryBuilder;
106
+ and(filter: string): PostgrestQueryBuilder;
107
+ not_(): PostgrestQueryBuilder;
108
+ order(column: string, ascending?: boolean): PostgrestQueryBuilder;
109
+ limit(n: number): PostgrestQueryBuilder;
110
+ offset(n: number): PostgrestQueryBuilder;
111
+ range(from: number, to: number): PostgrestQueryBuilder;
112
+ single(): PostgrestQueryBuilder;
113
+ maybeSingle(): PostgrestQueryBuilder;
114
+ then<T>(onFulfilled: (value: any) => T, onRejected?: (reason: any) => any): Promise<T>;
115
+ catch<T>(onRejected: (reason: any) => T): Promise<any>;
116
+ execute(): Promise<{
117
+ data: any;
118
+ error: PostgrestError | null;
119
+ }>;
120
+ }
121
+ declare class AuthClient {
122
+ private url;
123
+ private key;
124
+ private projectRef;
125
+ currentSession: Session | null;
126
+ currentUser: User | null;
127
+ private listeners;
128
+ constructor(url: string, key: string, projectRef: string);
129
+ onAuthStateChange(cb: (event: AuthChangeEventType, session: Session | null) => void): () => void;
130
+ private emit;
131
+ private getHeaders;
132
+ initialize(): Promise<void>;
133
+ private persist;
134
+ signUp(body: {
135
+ email: string;
136
+ password: string;
137
+ }): Promise<{
138
+ data: Session | null;
139
+ error: AuthError | null;
140
+ }>;
141
+ signInWithPassword(body: {
142
+ email: string;
143
+ password: string;
144
+ }): Promise<{
145
+ data: Session | null;
146
+ error: AuthError | null;
147
+ }>;
148
+ signInWithOAuth(options: {
149
+ provider: string;
150
+ redirectTo?: string;
151
+ codeChallenge?: string;
152
+ }): string;
153
+ signInWithOtp(body: {
154
+ email?: string;
155
+ phone?: string;
156
+ }): Promise<{
157
+ error: AuthError | null;
158
+ }>;
159
+ signInWithIdToken(body: {
160
+ provider: string;
161
+ idToken: string;
162
+ }): Promise<{
163
+ data: Session | null;
164
+ error: AuthError | null;
165
+ }>;
166
+ signInAnonymously(): Promise<{
167
+ data: Session | null;
168
+ error: AuthError | null;
169
+ }>;
170
+ reauthenticate(body: {
171
+ email: string;
172
+ password: string;
173
+ }): Promise<{
174
+ data: Session | null;
175
+ error: AuthError | null;
176
+ }>;
177
+ signOut(): Promise<{
178
+ error: AuthError | null;
179
+ }>;
180
+ setAuth(token: string): void;
181
+ setSession(session: Session): void;
182
+ refreshSession(): Promise<{
183
+ data: Session | null;
184
+ error: AuthError | null;
185
+ }>;
186
+ updateUser(attributes: Record<string, any>, options?: {
187
+ emailRedirectTo?: string;
188
+ }): Promise<{
189
+ data: User | null;
190
+ error: AuthError | null;
191
+ }>;
192
+ resetPasswordForEmail(email: string, options?: {
193
+ redirectTo?: string;
194
+ }): Promise<{
195
+ error: AuthError | null;
196
+ }>;
197
+ enroll(body: {
198
+ friendlyName?: string;
199
+ }): Promise<{
200
+ data: Factor | null;
201
+ error: AuthError | null;
202
+ }>;
203
+ verifyFactor(body: {
204
+ factorId: string;
205
+ code: string;
206
+ challengeId?: string;
207
+ }): Promise<{
208
+ data: any;
209
+ error: AuthError | null;
210
+ }>;
211
+ createChallenge(body: {
212
+ factorId: string;
213
+ }): Promise<{
214
+ data: any;
215
+ error: AuthError | null;
216
+ }>;
217
+ verifyChallenge(body: {
218
+ challengeId: string;
219
+ code: string;
220
+ }): Promise<{
221
+ data: any;
222
+ error: AuthError | null;
223
+ }>;
224
+ unenroll(body: {
225
+ factorId: string;
226
+ }): Promise<{
227
+ error: AuthError | null;
228
+ }>;
229
+ listFactors(): Promise<{
230
+ data: Factor[] | null;
231
+ error: AuthError | null;
232
+ }>;
233
+ }
234
+ declare class StorageClient {
235
+ private url;
236
+ private key;
237
+ private projectRef;
238
+ private getAuthHeaders;
239
+ constructor(url: string, key: string, projectRef: string, getAuthHeaders: () => Record<string, string>);
240
+ from(bucketId: string): StorageFileApi;
241
+ createBucket(id: string, options?: {
242
+ public?: boolean;
243
+ file_size_limit?: number;
244
+ allowed_mime_types?: string[];
245
+ }): Promise<{
246
+ data: any;
247
+ error: PostgrestError | null;
248
+ }>;
249
+ deleteBucket(id: string): Promise<{
250
+ data: any;
251
+ error: PostgrestError | null;
252
+ }>;
253
+ listBuckets(): Promise<{
254
+ data: any[] | null;
255
+ error: PostgrestError | null;
256
+ }>;
257
+ }
258
+ declare class StorageFileApi {
259
+ private url;
260
+ private key;
261
+ private projectRef;
262
+ private getAuthHeaders;
263
+ private bucketId;
264
+ constructor(url: string, key: string, projectRef: string, getAuthHeaders: () => Record<string, string>, bucketId: string);
265
+ private getHeaders;
266
+ upload(path: string, file: File | Blob): Promise<{
267
+ data: any;
268
+ error: PostgrestError | null;
269
+ }>;
270
+ download(path: string): Promise<{
271
+ data: Blob | null;
272
+ error: PostgrestError | null;
273
+ }>;
274
+ remove(paths: string[]): Promise<{
275
+ error: PostgrestError | null;
276
+ }>;
277
+ move(fromPath: string, toPath: string): Promise<{
278
+ error: PostgrestError | null;
279
+ }>;
280
+ copy(fromPath: string, toPath: string): Promise<{
281
+ error: PostgrestError | null;
282
+ }>;
283
+ createSignedUrl(path: string, expiresIn?: number): Promise<{
284
+ data: string | null;
285
+ error: PostgrestError | null;
286
+ }>;
287
+ getPublicUrl(path: string, download?: boolean): string;
288
+ }
289
+ declare class RealtimeClient {
290
+ private url;
291
+ private key;
292
+ private projectRef;
293
+ private ws;
294
+ private channels;
295
+ private reconnectTimer;
296
+ private connected;
297
+ constructor(url: string, key: string, projectRef: string);
298
+ connect(): void;
299
+ disconnect(): void;
300
+ on(table: string): {
301
+ subscribe: (cb: (payload: RealtimePayload) => void) => RealtimeSubscription;
302
+ };
303
+ channel(table: string, filter?: PostgresCDCConfig): RealtimeChannel;
304
+ send(payload: any): void;
305
+ get isConnected(): boolean;
306
+ removeChannel(name: string): void;
307
+ }
308
+ declare class RealtimeChannel {
309
+ private client;
310
+ private name;
311
+ private table;
312
+ private filter?;
313
+ private _subscribed;
314
+ private cdcCallbacks;
315
+ private presenceCallbacks;
316
+ private broadcastCallbacks;
317
+ private presenceState;
318
+ constructor(client: RealtimeClient, name: string, table: string, filter?: PostgresCDCConfig);
319
+ get subscribed(): boolean;
320
+ subscribe(): RealtimeChannel;
321
+ resubscribe(): void;
322
+ unsubscribe(): void;
323
+ on(event: 'INSERT' | 'UPDATE' | 'DELETE' | '*', cb: (payload: RealtimePayload) => void): RealtimeSubscription;
324
+ onPresence(cb: (payload: any) => void): () => void;
325
+ onBroadcast(eventOrCb: string | ((payload: any) => void), cb?: (payload: any) => void): () => void;
326
+ broadcast(event: string, payload?: any): void;
327
+ track(userState: Record<string, any>): void;
328
+ get stream(): {
329
+ on: (event: string, cb: (payload: any) => void) => () => void;
330
+ };
331
+ handleMessage(msg: any): void;
332
+ }
333
+ declare class RealtimeSubscription {
334
+ private client;
335
+ private table;
336
+ private event;
337
+ private callback;
338
+ private _active;
339
+ constructor(client: RealtimeClient, table: string, event: string, callback: (payload: RealtimePayload) => void);
340
+ _setActive(active: boolean): void;
341
+ subscribe(): void;
342
+ unsubscribe(): void;
343
+ }
344
+ declare class FunctionsClient {
345
+ private url;
346
+ private key;
347
+ private projectRef;
348
+ private getAuthHeaders;
349
+ constructor(url: string, key: string, projectRef: string, getAuthHeaders: () => Record<string, string>);
350
+ invoke(functionName: string, options?: {
351
+ body?: any;
352
+ }): Promise<{
353
+ data: any;
354
+ error: FunctionsError | null;
355
+ }>;
356
+ }
357
+ export {};