@redbase/sdk 0.1.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.
@@ -0,0 +1,165 @@
1
+ import { SupabaseClient } from '@supabase/supabase-js';
2
+ export { AuthSession, AuthUser, FunctionRegion, FunctionsError, FunctionsFetchError, FunctionsHttpError, FunctionsRelayError, PostgrestError, PostgrestMaybeSingleResponse, PostgrestResponse, PostgrestSingleResponse, QueryData, QueryError, QueryResult, StorageApiError, SupabaseClient, SupabaseClientOptions, createClient as createSupabaseClient } from '@supabase/supabase-js';
3
+ export { AuthApiError, AuthError, AuthResponse, Provider, Session, SignInWithPasswordCredentials, SignUpWithPasswordCredentials, User, UserResponse } from '@supabase/auth-js';
4
+ export { REALTIME_LISTEN_TYPES, REALTIME_POSTGRES_CHANGES_LISTEN_EVENT, REALTIME_PRESENCE_LISTEN_EVENTS, REALTIME_SUBSCRIBE_STATES, RealtimeChannel, RealtimePostgresChangesPayload } from '@supabase/realtime-js';
5
+
6
+ /**
7
+ * Options for sending an email via RedBase email worker.
8
+ */
9
+ interface EmailSendOptions {
10
+ /** Recipient email address(es). */
11
+ to: string | string[];
12
+ /** Email subject line. */
13
+ subject: string;
14
+ /** HTML body content. */
15
+ html: string;
16
+ /** Plain text body content (optional fallback). */
17
+ text?: string;
18
+ /** Reply-to address (optional). */
19
+ replyTo?: string;
20
+ /** CC recipients (optional). */
21
+ cc?: string | string[];
22
+ /** BCC recipients (optional). */
23
+ bcc?: string | string[];
24
+ }
25
+ /**
26
+ * Response from the email send endpoint.
27
+ */
28
+ interface EmailSendResponse {
29
+ /** Whether the email was queued successfully. */
30
+ success: boolean;
31
+ /** Message ID if successful. */
32
+ messageId?: string;
33
+ /** Error message if failed. */
34
+ error?: string;
35
+ }
36
+ /**
37
+ * Email client for sending transactional emails via RedBase.
38
+ *
39
+ * **Important:** Use with `SERVICE_ROLE_KEY` on the server only.
40
+ * The email endpoint requires elevated privileges and should never
41
+ * be called from client-side code with the anon key.
42
+ */
43
+ interface EmailClient {
44
+ /**
45
+ * Send a transactional email.
46
+ *
47
+ * @param options - Email options (to, subject, html, text, etc.)
48
+ * @returns Promise resolving to the send result
49
+ *
50
+ * @example
51
+ * ```ts
52
+ * const { success, messageId, error } = await rb.email.send({
53
+ * to: 'user@example.com',
54
+ * subject: 'Welcome!',
55
+ * html: '<h1>Hello</h1>',
56
+ * text: 'Hello',
57
+ * })
58
+ * ```
59
+ */
60
+ send(options: EmailSendOptions): Promise<EmailSendResponse>;
61
+ }
62
+
63
+ /**
64
+ * RedBase client options.
65
+ * See @supabase/supabase-js SupabaseClientOptions for full documentation.
66
+ */
67
+ interface RedbaseClientOptions {
68
+ auth?: {
69
+ autoRefreshToken?: boolean;
70
+ persistSession?: boolean;
71
+ detectSessionInUrl?: boolean;
72
+ storage?: unknown;
73
+ storageKey?: string;
74
+ flowType?: 'implicit' | 'pkce';
75
+ };
76
+ global?: {
77
+ headers?: Record<string, string>;
78
+ fetch?: typeof fetch;
79
+ };
80
+ db?: {
81
+ schema?: string;
82
+ };
83
+ realtime?: {
84
+ params?: Record<string, unknown>;
85
+ };
86
+ }
87
+ /**
88
+ * RedBase client type - a Supabase client with email capabilities.
89
+ *
90
+ * Use with your Database types for full type safety:
91
+ * ```ts
92
+ * import type { Database } from './database.types'
93
+ * const rb = createClient<Database>(url, key)
94
+ * ```
95
+ */
96
+ type RedbaseClient<Database = unknown> = SupabaseClient<Database> & {
97
+ /**
98
+ * Email client for sending transactional emails.
99
+ * **Server-side only.** Requires `SERVICE_ROLE_KEY`.
100
+ */
101
+ email: EmailClient;
102
+ };
103
+ /**
104
+ * Creates a RedBase client instance.
105
+ *
106
+ * The client is a thin wrapper around `@supabase/supabase-js` that provides:
107
+ * - Full Supabase client compatibility (`auth`, `from`, `storage`, etc.)
108
+ * - Additional `email` helper for sending transactional emails
109
+ *
110
+ * @param redbaseUrl - The RedBase API URL (e.g., `https://api.payagenda.com` or `http://localhost:8000`)
111
+ * @param redbaseKey - The API key (anon key for client, service role key for server)
112
+ * @param options - Optional client configuration
113
+ * @returns A RedBase client instance
114
+ *
115
+ * @example
116
+ * ```ts
117
+ * // Client-side usage (anon key)
118
+ * import { createClient } from '@redbase/sdk'
119
+ *
120
+ * const rb = createClient(
121
+ * import.meta.env.VITE_REDBASE_URL,
122
+ * import.meta.env.VITE_REDBASE_ANON_KEY
123
+ * )
124
+ *
125
+ * // Use like Supabase client
126
+ * const { data } = await rb.from('users').select('*')
127
+ * const { data: session } = await rb.auth.getSession()
128
+ * ```
129
+ *
130
+ * @example
131
+ * ```ts
132
+ * // With Database types
133
+ * import { createClient } from '@redbase/sdk'
134
+ * import type { Database } from './database.types'
135
+ *
136
+ * const rb = createClient<Database>(
137
+ * import.meta.env.VITE_REDBASE_URL,
138
+ * import.meta.env.VITE_REDBASE_ANON_KEY
139
+ * )
140
+ *
141
+ * // Fully typed queries
142
+ * const { data } = await rb.from('users').select('id, email')
143
+ * ```
144
+ *
145
+ * @example
146
+ * ```ts
147
+ * // Server-side usage (service role key for email)
148
+ * import { createClient } from '@redbase/sdk'
149
+ *
150
+ * const rb = createClient(
151
+ * process.env.REDBASE_URL!,
152
+ * process.env.REDBASE_SERVICE_ROLE_KEY!
153
+ * )
154
+ *
155
+ * // Send transactional email
156
+ * const { success, error } = await rb.email.send({
157
+ * to: 'user@example.com',
158
+ * subject: 'Welcome!',
159
+ * html: '<h1>Welcome to our app!</h1>',
160
+ * })
161
+ * ```
162
+ */
163
+ declare function createClient<Database = unknown>(redbaseUrl: string, redbaseKey: string, options?: RedbaseClientOptions): RedbaseClient<Database>;
164
+
165
+ export { type EmailClient, type EmailSendOptions, type EmailSendResponse, type RedbaseClient, type RedbaseClientOptions, createClient };
@@ -0,0 +1,165 @@
1
+ import { SupabaseClient } from '@supabase/supabase-js';
2
+ export { AuthSession, AuthUser, FunctionRegion, FunctionsError, FunctionsFetchError, FunctionsHttpError, FunctionsRelayError, PostgrestError, PostgrestMaybeSingleResponse, PostgrestResponse, PostgrestSingleResponse, QueryData, QueryError, QueryResult, StorageApiError, SupabaseClient, SupabaseClientOptions, createClient as createSupabaseClient } from '@supabase/supabase-js';
3
+ export { AuthApiError, AuthError, AuthResponse, Provider, Session, SignInWithPasswordCredentials, SignUpWithPasswordCredentials, User, UserResponse } from '@supabase/auth-js';
4
+ export { REALTIME_LISTEN_TYPES, REALTIME_POSTGRES_CHANGES_LISTEN_EVENT, REALTIME_PRESENCE_LISTEN_EVENTS, REALTIME_SUBSCRIBE_STATES, RealtimeChannel, RealtimePostgresChangesPayload } from '@supabase/realtime-js';
5
+
6
+ /**
7
+ * Options for sending an email via RedBase email worker.
8
+ */
9
+ interface EmailSendOptions {
10
+ /** Recipient email address(es). */
11
+ to: string | string[];
12
+ /** Email subject line. */
13
+ subject: string;
14
+ /** HTML body content. */
15
+ html: string;
16
+ /** Plain text body content (optional fallback). */
17
+ text?: string;
18
+ /** Reply-to address (optional). */
19
+ replyTo?: string;
20
+ /** CC recipients (optional). */
21
+ cc?: string | string[];
22
+ /** BCC recipients (optional). */
23
+ bcc?: string | string[];
24
+ }
25
+ /**
26
+ * Response from the email send endpoint.
27
+ */
28
+ interface EmailSendResponse {
29
+ /** Whether the email was queued successfully. */
30
+ success: boolean;
31
+ /** Message ID if successful. */
32
+ messageId?: string;
33
+ /** Error message if failed. */
34
+ error?: string;
35
+ }
36
+ /**
37
+ * Email client for sending transactional emails via RedBase.
38
+ *
39
+ * **Important:** Use with `SERVICE_ROLE_KEY` on the server only.
40
+ * The email endpoint requires elevated privileges and should never
41
+ * be called from client-side code with the anon key.
42
+ */
43
+ interface EmailClient {
44
+ /**
45
+ * Send a transactional email.
46
+ *
47
+ * @param options - Email options (to, subject, html, text, etc.)
48
+ * @returns Promise resolving to the send result
49
+ *
50
+ * @example
51
+ * ```ts
52
+ * const { success, messageId, error } = await rb.email.send({
53
+ * to: 'user@example.com',
54
+ * subject: 'Welcome!',
55
+ * html: '<h1>Hello</h1>',
56
+ * text: 'Hello',
57
+ * })
58
+ * ```
59
+ */
60
+ send(options: EmailSendOptions): Promise<EmailSendResponse>;
61
+ }
62
+
63
+ /**
64
+ * RedBase client options.
65
+ * See @supabase/supabase-js SupabaseClientOptions for full documentation.
66
+ */
67
+ interface RedbaseClientOptions {
68
+ auth?: {
69
+ autoRefreshToken?: boolean;
70
+ persistSession?: boolean;
71
+ detectSessionInUrl?: boolean;
72
+ storage?: unknown;
73
+ storageKey?: string;
74
+ flowType?: 'implicit' | 'pkce';
75
+ };
76
+ global?: {
77
+ headers?: Record<string, string>;
78
+ fetch?: typeof fetch;
79
+ };
80
+ db?: {
81
+ schema?: string;
82
+ };
83
+ realtime?: {
84
+ params?: Record<string, unknown>;
85
+ };
86
+ }
87
+ /**
88
+ * RedBase client type - a Supabase client with email capabilities.
89
+ *
90
+ * Use with your Database types for full type safety:
91
+ * ```ts
92
+ * import type { Database } from './database.types'
93
+ * const rb = createClient<Database>(url, key)
94
+ * ```
95
+ */
96
+ type RedbaseClient<Database = unknown> = SupabaseClient<Database> & {
97
+ /**
98
+ * Email client for sending transactional emails.
99
+ * **Server-side only.** Requires `SERVICE_ROLE_KEY`.
100
+ */
101
+ email: EmailClient;
102
+ };
103
+ /**
104
+ * Creates a RedBase client instance.
105
+ *
106
+ * The client is a thin wrapper around `@supabase/supabase-js` that provides:
107
+ * - Full Supabase client compatibility (`auth`, `from`, `storage`, etc.)
108
+ * - Additional `email` helper for sending transactional emails
109
+ *
110
+ * @param redbaseUrl - The RedBase API URL (e.g., `https://api.payagenda.com` or `http://localhost:8000`)
111
+ * @param redbaseKey - The API key (anon key for client, service role key for server)
112
+ * @param options - Optional client configuration
113
+ * @returns A RedBase client instance
114
+ *
115
+ * @example
116
+ * ```ts
117
+ * // Client-side usage (anon key)
118
+ * import { createClient } from '@redbase/sdk'
119
+ *
120
+ * const rb = createClient(
121
+ * import.meta.env.VITE_REDBASE_URL,
122
+ * import.meta.env.VITE_REDBASE_ANON_KEY
123
+ * )
124
+ *
125
+ * // Use like Supabase client
126
+ * const { data } = await rb.from('users').select('*')
127
+ * const { data: session } = await rb.auth.getSession()
128
+ * ```
129
+ *
130
+ * @example
131
+ * ```ts
132
+ * // With Database types
133
+ * import { createClient } from '@redbase/sdk'
134
+ * import type { Database } from './database.types'
135
+ *
136
+ * const rb = createClient<Database>(
137
+ * import.meta.env.VITE_REDBASE_URL,
138
+ * import.meta.env.VITE_REDBASE_ANON_KEY
139
+ * )
140
+ *
141
+ * // Fully typed queries
142
+ * const { data } = await rb.from('users').select('id, email')
143
+ * ```
144
+ *
145
+ * @example
146
+ * ```ts
147
+ * // Server-side usage (service role key for email)
148
+ * import { createClient } from '@redbase/sdk'
149
+ *
150
+ * const rb = createClient(
151
+ * process.env.REDBASE_URL!,
152
+ * process.env.REDBASE_SERVICE_ROLE_KEY!
153
+ * )
154
+ *
155
+ * // Send transactional email
156
+ * const { success, error } = await rb.email.send({
157
+ * to: 'user@example.com',
158
+ * subject: 'Welcome!',
159
+ * html: '<h1>Welcome to our app!</h1>',
160
+ * })
161
+ * ```
162
+ */
163
+ declare function createClient<Database = unknown>(redbaseUrl: string, redbaseKey: string, options?: RedbaseClientOptions): RedbaseClient<Database>;
164
+
165
+ export { type EmailClient, type EmailSendOptions, type EmailSendResponse, type RedbaseClient, type RedbaseClientOptions, createClient };