@supatype/client 0.1.0-alpha.6

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 (71) hide show
  1. package/.turbo/turbo-build.log +4 -0
  2. package/.turbo/turbo-test.log +7 -0
  3. package/.turbo/turbo-typecheck.log +4 -0
  4. package/dist/auth.d.ts +243 -0
  5. package/dist/auth.d.ts.map +1 -0
  6. package/dist/auth.js +560 -0
  7. package/dist/auth.js.map +1 -0
  8. package/dist/error-codes-doc.d.ts +31 -0
  9. package/dist/error-codes-doc.d.ts.map +1 -0
  10. package/dist/error-codes-doc.js +294 -0
  11. package/dist/error-codes-doc.js.map +1 -0
  12. package/dist/errors.d.ts +197 -0
  13. package/dist/errors.d.ts.map +1 -0
  14. package/dist/errors.js +162 -0
  15. package/dist/errors.js.map +1 -0
  16. package/dist/fetch-with-retry.d.ts +49 -0
  17. package/dist/fetch-with-retry.d.ts.map +1 -0
  18. package/dist/fetch-with-retry.js +150 -0
  19. package/dist/fetch-with-retry.js.map +1 -0
  20. package/dist/index.d.ts +137 -0
  21. package/dist/index.d.ts.map +1 -0
  22. package/dist/index.js +225 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/query.d.ts +53 -0
  25. package/dist/query.d.ts.map +1 -0
  26. package/dist/query.js +216 -0
  27. package/dist/query.js.map +1 -0
  28. package/dist/realtime.d.ts +69 -0
  29. package/dist/realtime.d.ts.map +1 -0
  30. package/dist/realtime.js +279 -0
  31. package/dist/realtime.js.map +1 -0
  32. package/dist/retry.d.ts +24 -0
  33. package/dist/retry.d.ts.map +1 -0
  34. package/dist/retry.js +25 -0
  35. package/dist/retry.js.map +1 -0
  36. package/dist/serverless-docs.d.ts +38 -0
  37. package/dist/serverless-docs.d.ts.map +1 -0
  38. package/dist/serverless-docs.js +83 -0
  39. package/dist/serverless-docs.js.map +1 -0
  40. package/dist/storage.d.ts +79 -0
  41. package/dist/storage.d.ts.map +1 -0
  42. package/dist/storage.js +130 -0
  43. package/dist/storage.js.map +1 -0
  44. package/dist/types.d.ts +141 -0
  45. package/dist/types.d.ts.map +1 -0
  46. package/dist/types.js +3 -0
  47. package/dist/types.js.map +1 -0
  48. package/package.json +26 -0
  49. package/src/auth.ts +713 -0
  50. package/src/error-codes-doc.ts +315 -0
  51. package/src/errors.ts +201 -0
  52. package/src/fetch-with-retry.ts +200 -0
  53. package/src/index.ts +418 -0
  54. package/src/query.ts +280 -0
  55. package/src/realtime.ts +418 -0
  56. package/src/retry.ts +35 -0
  57. package/src/serverless-docs.ts +107 -0
  58. package/src/storage.ts +182 -0
  59. package/src/types.ts +184 -0
  60. package/tests/auth.test.ts +282 -0
  61. package/tests/mfa-totp-integration.test.ts +359 -0
  62. package/tests/query.test.ts +286 -0
  63. package/tests/rate-limit-integration.test.ts +185 -0
  64. package/tests/realtime-multi-tenant-integration.test.ts +372 -0
  65. package/tests/retry-integration.test.ts +212 -0
  66. package/tests/serverless.test.ts +115 -0
  67. package/tests/storage-quota-integration.test.ts +189 -0
  68. package/tests/storage-upload-limit-integration.test.ts +185 -0
  69. package/tests/types.test.ts +123 -0
  70. package/tsconfig.json +11 -0
  71. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,315 @@
1
+ /**
2
+ * Error codes documentation — Gap Appendices task 35
3
+ *
4
+ * Published list of all Supatype error codes with descriptions and suggested
5
+ * fixes. Accessible at docs.supatype.io/errors.
6
+ *
7
+ * Each SDK error includes a `helpUrl` field linking to the relevant section
8
+ * on the documentation page.
9
+ */
10
+
11
+ export interface ErrorCodeEntry {
12
+ /** Machine-readable error code (e.g. "AUTH_INVALID_CREDENTIALS"). */
13
+ code: string
14
+ /** Human-readable short description. */
15
+ description: string
16
+ /** Suggested fix or resolution. */
17
+ suggestion: string
18
+ /** HTTP status code typically associated with this error. */
19
+ httpStatus?: number | undefined
20
+ /** Category grouping. */
21
+ category: "auth" | "postgrest" | "storage" | "realtime" | "network"
22
+ }
23
+
24
+ export const ERROR_CODES_DOCUMENTATION: readonly ErrorCodeEntry[] = [
25
+ // ── Auth errors ──────────────────────────────────────────────────────────
26
+ {
27
+ code: "AUTH_INVALID_CREDENTIALS",
28
+ description: "The email/password combination is incorrect.",
29
+ suggestion: "Check the email and password. If forgotten, use resetPasswordForEmail().",
30
+ httpStatus: 400,
31
+ category: "auth",
32
+ },
33
+ {
34
+ code: "AUTH_USER_NOT_FOUND",
35
+ description: "No user exists with the provided identifier.",
36
+ suggestion: "Verify the email address. The user may need to sign up first.",
37
+ httpStatus: 404,
38
+ category: "auth",
39
+ },
40
+ {
41
+ code: "AUTH_EMAIL_NOT_CONFIRMED",
42
+ description: "The user's email has not been confirmed yet.",
43
+ suggestion: "Check inbox for the confirmation email. Use auth.resend({ type: 'signup' }) to re-send.",
44
+ httpStatus: 403,
45
+ category: "auth",
46
+ },
47
+ {
48
+ code: "AUTH_PHONE_NOT_CONFIRMED",
49
+ description: "The user's phone number has not been verified.",
50
+ suggestion: "Complete the phone OTP verification flow.",
51
+ httpStatus: 403,
52
+ category: "auth",
53
+ },
54
+ {
55
+ code: "AUTH_SESSION_EXPIRED",
56
+ description: "The session has expired and the refresh token is no longer valid.",
57
+ suggestion: "Sign the user in again. Implement automatic token refresh with onAuthStateChange.",
58
+ httpStatus: 401,
59
+ category: "auth",
60
+ },
61
+ {
62
+ code: "AUTH_INVALID_TOKEN",
63
+ description: "The provided JWT is malformed, expired, or signed with a different secret.",
64
+ suggestion: "Ensure the token is from the correct project. Check expiry. Re-authenticate.",
65
+ httpStatus: 401,
66
+ category: "auth",
67
+ },
68
+ {
69
+ code: "AUTH_MFA_REQUIRED",
70
+ description: "Multi-factor authentication is required to complete this action.",
71
+ suggestion: "Call mfa.challenge() and mfa.verify() with the user's TOTP code.",
72
+ httpStatus: 403,
73
+ category: "auth",
74
+ },
75
+ {
76
+ code: "AUTH_MFA_CHALLENGE_EXPIRED",
77
+ description: "The MFA challenge has expired.",
78
+ suggestion: "Create a new challenge with mfa.challenge() and try again.",
79
+ httpStatus: 400,
80
+ category: "auth",
81
+ },
82
+ {
83
+ code: "AUTH_MFA_VERIFICATION_FAILED",
84
+ description: "The MFA verification code is incorrect.",
85
+ suggestion: "Ensure the TOTP code is current (codes rotate every 30 seconds).",
86
+ httpStatus: 400,
87
+ category: "auth",
88
+ },
89
+ {
90
+ code: "AUTH_WEAK_PASSWORD",
91
+ description: "The password does not meet the minimum strength requirements.",
92
+ suggestion: "Use a password with at least 8 characters including mixed case and numbers.",
93
+ httpStatus: 422,
94
+ category: "auth",
95
+ },
96
+ {
97
+ code: "AUTH_USER_ALREADY_EXISTS",
98
+ description: "A user with this email or phone already exists.",
99
+ suggestion: "Use signInWithPassword() instead, or try a different email.",
100
+ httpStatus: 409,
101
+ category: "auth",
102
+ },
103
+ {
104
+ code: "AUTH_OAUTH_CALLBACK_ERROR",
105
+ description: "The OAuth provider returned an error during the callback.",
106
+ suggestion: "Check the provider configuration (client ID, secret, redirect URL).",
107
+ httpStatus: 400,
108
+ category: "auth",
109
+ },
110
+ {
111
+ code: "AUTH_MAGIC_LINK_EXPIRED",
112
+ description: "The magic link has expired (default: 10 minutes).",
113
+ suggestion: "Request a new magic link with signInWithOtp({ email }).",
114
+ httpStatus: 400,
115
+ category: "auth",
116
+ },
117
+
118
+ // ── PostgREST errors ─────────────────────────────────────────────────────
119
+ {
120
+ code: "PGRST301",
121
+ description: "JWT expired or missing. PostgREST could not authenticate the request.",
122
+ suggestion: "Refresh the user's session or re-authenticate. Check that the apikey header is set.",
123
+ httpStatus: 401,
124
+ category: "postgrest",
125
+ },
126
+ {
127
+ code: "PGRST302",
128
+ description: "Permission denied. RLS policy blocked access to the requested resource.",
129
+ suggestion: "Review your access rules in the schema. Ensure the user has the required role.",
130
+ httpStatus: 403,
131
+ category: "postgrest",
132
+ },
133
+ {
134
+ code: "PGRST116",
135
+ description: "No rows returned when a single row was expected.",
136
+ suggestion: "Use .maybeSingle() instead of .single() if the record may not exist.",
137
+ httpStatus: 406,
138
+ category: "postgrest",
139
+ },
140
+ {
141
+ code: "PGRST204",
142
+ description: "PostgREST schema cache is stale. The table or function may have changed.",
143
+ suggestion: "PostgREST will reload its cache automatically. Retry the request.",
144
+ httpStatus: 503,
145
+ category: "postgrest",
146
+ },
147
+ {
148
+ code: "PGRST23503",
149
+ description: "Foreign key constraint violation. The referenced record does not exist.",
150
+ suggestion: "Ensure the related record exists before creating/updating. Check relation fields.",
151
+ httpStatus: 409,
152
+ category: "postgrest",
153
+ },
154
+ {
155
+ code: "PGRST23505",
156
+ description: "Unique constraint violation. A record with this value already exists.",
157
+ suggestion: "Use .upsert() for insert-or-update, or check for existing records first.",
158
+ httpStatus: 409,
159
+ category: "postgrest",
160
+ },
161
+ {
162
+ code: "PGRST23502",
163
+ description: "Not-null constraint violation. A required field is missing.",
164
+ suggestion: "Include all required fields in the insert/update payload.",
165
+ httpStatus: 400,
166
+ category: "postgrest",
167
+ },
168
+ {
169
+ code: "PGRST23514",
170
+ description: "Check constraint violation. A field value does not satisfy the constraint.",
171
+ suggestion: "Ensure enum values match declared options. Check field validation rules.",
172
+ httpStatus: 400,
173
+ category: "postgrest",
174
+ },
175
+ {
176
+ code: "PGRST22P02",
177
+ description: "Invalid input syntax. The value cannot be cast to the expected type.",
178
+ suggestion: "Check that field values match the expected types (e.g., UUID format, number format).",
179
+ httpStatus: 400,
180
+ category: "postgrest",
181
+ },
182
+ {
183
+ code: "PGRST42P01",
184
+ description: "Table does not exist. The schema may need to be pushed.",
185
+ suggestion: "Run `npx supatype push` to apply your schema to the database.",
186
+ httpStatus: 404,
187
+ category: "postgrest",
188
+ },
189
+ {
190
+ code: "PGRST42703",
191
+ description: "Column does not exist. The field may have been renamed or removed.",
192
+ suggestion: "Check your query column names against the current schema.",
193
+ httpStatus: 400,
194
+ category: "postgrest",
195
+ },
196
+
197
+ // ── Storage errors ───────────────────────────────────────────────────────
198
+ {
199
+ code: "STORAGE_OBJECT_NOT_FOUND",
200
+ description: "The requested file does not exist in the bucket.",
201
+ suggestion: "Verify the file path. List bucket contents with storage.from('bucket').list().",
202
+ httpStatus: 404,
203
+ category: "storage",
204
+ },
205
+ {
206
+ code: "STORAGE_BUCKET_NOT_FOUND",
207
+ description: "The specified bucket does not exist.",
208
+ suggestion: "Check the bucket name. Buckets are created from your schema's storage fields.",
209
+ httpStatus: 404,
210
+ category: "storage",
211
+ },
212
+ {
213
+ code: "STORAGE_FILE_TOO_LARGE",
214
+ description: "The uploaded file exceeds the maximum allowed size.",
215
+ suggestion: "Compress the file or request a larger limit. Check field.image({ maxSize }) config.",
216
+ httpStatus: 413,
217
+ category: "storage",
218
+ },
219
+ {
220
+ code: "STORAGE_INVALID_FILE_TYPE",
221
+ description: "The file's Content-Type is not in the bucket's allowed types list.",
222
+ suggestion: "Check field.image({ accept: [...] }) or field.file({ accept: [...] }) configuration.",
223
+ httpStatus: 415,
224
+ category: "storage",
225
+ },
226
+ {
227
+ code: "STORAGE_QUOTA_EXCEEDED",
228
+ description: "Uploading this file would exceed your project's total storage quota.",
229
+ suggestion: "Delete unused files or upgrade your plan for more storage.",
230
+ httpStatus: 507,
231
+ category: "storage",
232
+ },
233
+ {
234
+ code: "STORAGE_PRESIGNED_URL_EXPIRED",
235
+ description: "The pre-signed URL has expired.",
236
+ suggestion: "Generate a new pre-signed URL with createSignedUrl().",
237
+ httpStatus: 403,
238
+ category: "storage",
239
+ },
240
+
241
+ // ── Realtime errors ──────────────────────────────────────────────────────
242
+ {
243
+ code: "REALTIME_CONNECTION_FAILED",
244
+ description: "WebSocket connection to the Realtime server could not be established.",
245
+ suggestion: "Check network connectivity and that the Realtime service is running.",
246
+ category: "realtime",
247
+ },
248
+ {
249
+ code: "REALTIME_SUBSCRIPTION_DENIED",
250
+ description: "The subscription was denied due to RLS or authentication.",
251
+ suggestion: "Ensure the user has read access to the subscribed table.",
252
+ category: "realtime",
253
+ },
254
+ {
255
+ code: "REALTIME_CHANNEL_ERROR",
256
+ description: "An error occurred on the subscribed channel.",
257
+ suggestion: "Check the channel name and re-subscribe.",
258
+ category: "realtime",
259
+ },
260
+ {
261
+ code: "REALTIME_CONNECTION_LIMIT",
262
+ description: "The project's concurrent WebSocket connection limit has been exceeded.",
263
+ suggestion: "Close unused subscriptions or upgrade your plan for more connections.",
264
+ category: "realtime",
265
+ },
266
+ {
267
+ code: "REALTIME_HEARTBEAT_TIMEOUT",
268
+ description: "The Realtime server did not respond to heartbeat pings.",
269
+ suggestion: "Check server health. The client will attempt to reconnect automatically.",
270
+ category: "realtime",
271
+ },
272
+
273
+ // ── Network errors ───────────────────────────────────────────────────────
274
+ {
275
+ code: "NETWORK_TIMEOUT",
276
+ description: "The request timed out before receiving a response.",
277
+ suggestion: "Increase the timeout via createClient({ timeout: 60000 }) or check server load.",
278
+ category: "network",
279
+ },
280
+ {
281
+ code: "NETWORK_CONNECTION_REFUSED",
282
+ description: "The server refused the connection.",
283
+ suggestion: "Ensure the Supatype services are running. Check the URL in createClient().",
284
+ category: "network",
285
+ },
286
+ {
287
+ code: "NETWORK_DNS_FAILURE",
288
+ description: "DNS lookup failed for the API hostname.",
289
+ suggestion: "Check the URL. Verify DNS configuration and network connectivity.",
290
+ category: "network",
291
+ },
292
+ {
293
+ code: "RATE_LIMITED",
294
+ description: "Too many requests. The server returned HTTP 429.",
295
+ suggestion: "Wait for the Retry-After period. Implement client-side debouncing/throttling.",
296
+ httpStatus: 429,
297
+ category: "network",
298
+ },
299
+ ] as const
300
+
301
+ /**
302
+ * Look up documentation for a specific error code.
303
+ */
304
+ export function getErrorDocumentation(code: string): ErrorCodeEntry | undefined {
305
+ return ERROR_CODES_DOCUMENTATION.find((entry) => entry.code === code)
306
+ }
307
+
308
+ /**
309
+ * Get all error codes for a specific category.
310
+ */
311
+ export function getErrorCodesByCategory(
312
+ category: ErrorCodeEntry["category"],
313
+ ): readonly ErrorCodeEntry[] {
314
+ return ERROR_CODES_DOCUMENTATION.filter((entry) => entry.category === category)
315
+ }
package/src/errors.ts ADDED
@@ -0,0 +1,201 @@
1
+ /**
2
+ * Typed error hierarchy for the Supatype SDK.
3
+ * Every error has a machine-readable `code` field and optional `helpUrl`.
4
+ */
5
+
6
+ const DOCS_BASE = "https://docs.supatype.io/errors"
7
+
8
+ /**
9
+ * Base error class for all Supatype SDK errors.
10
+ */
11
+ export class SupatypeError extends Error {
12
+ readonly code: string
13
+ readonly helpUrl: string
14
+ readonly statusCode?: number | undefined
15
+
16
+ constructor(message: string, code: string, statusCode?: number) {
17
+ super(message)
18
+ this.name = "SupatypeError"
19
+ this.code = code
20
+ this.statusCode = statusCode
21
+ this.helpUrl = `${DOCS_BASE}#${code.toLowerCase()}`
22
+ }
23
+ }
24
+
25
+ /**
26
+ * Authentication errors (login failures, token issues, MFA).
27
+ */
28
+ export class AuthError extends SupatypeError {
29
+ constructor(message: string, code: string = "AUTH_ERROR", statusCode?: number) {
30
+ super(message, code, statusCode)
31
+ this.name = "AuthError"
32
+ }
33
+ }
34
+
35
+ /**
36
+ * PostgREST API errors with structured details.
37
+ */
38
+ export class PostgrestError extends SupatypeError {
39
+ readonly details: string | null
40
+ readonly hint: string | null
41
+
42
+ constructor(
43
+ message: string,
44
+ code: string = "PGRST000",
45
+ statusCode?: number,
46
+ details?: string | null,
47
+ hint?: string | null,
48
+ ) {
49
+ super(message, code, statusCode)
50
+ this.name = "PostgrestError"
51
+ this.details = details ?? null
52
+ this.hint = hint ?? null
53
+ }
54
+
55
+ /**
56
+ * Create from a PostgREST error response body.
57
+ */
58
+ static fromResponse(body: {
59
+ message?: string | undefined
60
+ code?: string | undefined
61
+ details?: string | undefined
62
+ hint?: string | undefined
63
+ }, statusCode: number): PostgrestError {
64
+ return new PostgrestError(
65
+ body.message || "PostgREST error",
66
+ body.code || `PGRST${statusCode}`,
67
+ statusCode,
68
+ body.details,
69
+ body.hint,
70
+ )
71
+ }
72
+ }
73
+
74
+ /**
75
+ * Storage service errors (upload/download failures).
76
+ */
77
+ export class StorageError extends SupatypeError {
78
+ constructor(message: string, code: string = "STORAGE_ERROR", statusCode?: number) {
79
+ super(message, code, statusCode)
80
+ this.name = "StorageError"
81
+ }
82
+ }
83
+
84
+ /**
85
+ * Realtime/WebSocket errors.
86
+ */
87
+ export class RealtimeError extends SupatypeError {
88
+ constructor(message: string, code: string = "REALTIME_ERROR") {
89
+ super(message, code)
90
+ this.name = "RealtimeError"
91
+ }
92
+ }
93
+
94
+ /**
95
+ * Network errors (connection failures, timeouts, DNS).
96
+ */
97
+ export class NetworkError extends SupatypeError {
98
+ constructor(message: string, code: string = "NETWORK_ERROR") {
99
+ super(message, code)
100
+ this.name = "NetworkError"
101
+ }
102
+ }
103
+
104
+ /**
105
+ * Rate limit errors with retry information.
106
+ */
107
+ export class RateLimitError extends SupatypeError {
108
+ readonly retryAfterSeconds: number
109
+
110
+ constructor(retryAfterSeconds: number) {
111
+ super(
112
+ `Rate limited. Retry after ${retryAfterSeconds} seconds.`,
113
+ "RATE_LIMITED",
114
+ 429,
115
+ )
116
+ this.name = "RateLimitError"
117
+ this.retryAfterSeconds = retryAfterSeconds
118
+ }
119
+ }
120
+
121
+ // ── Common error codes ────────────────────────────────────────────
122
+
123
+ export const AuthErrorCodes = {
124
+ INVALID_CREDENTIALS: "AUTH_INVALID_CREDENTIALS",
125
+ USER_NOT_FOUND: "AUTH_USER_NOT_FOUND",
126
+ EMAIL_NOT_CONFIRMED: "AUTH_EMAIL_NOT_CONFIRMED",
127
+ PHONE_NOT_CONFIRMED: "AUTH_PHONE_NOT_CONFIRMED",
128
+ SESSION_EXPIRED: "AUTH_SESSION_EXPIRED",
129
+ INVALID_TOKEN: "AUTH_INVALID_TOKEN",
130
+ MFA_REQUIRED: "AUTH_MFA_REQUIRED",
131
+ MFA_CHALLENGE_EXPIRED: "AUTH_MFA_CHALLENGE_EXPIRED",
132
+ MFA_VERIFICATION_FAILED: "AUTH_MFA_VERIFICATION_FAILED",
133
+ WEAK_PASSWORD: "AUTH_WEAK_PASSWORD",
134
+ USER_ALREADY_EXISTS: "AUTH_USER_ALREADY_EXISTS",
135
+ OAUTH_CALLBACK_ERROR: "AUTH_OAUTH_CALLBACK_ERROR",
136
+ MAGIC_LINK_EXPIRED: "AUTH_MAGIC_LINK_EXPIRED",
137
+ } as const
138
+
139
+ export const StorageErrorCodes = {
140
+ OBJECT_NOT_FOUND: "STORAGE_OBJECT_NOT_FOUND",
141
+ BUCKET_NOT_FOUND: "STORAGE_BUCKET_NOT_FOUND",
142
+ FILE_TOO_LARGE: "STORAGE_FILE_TOO_LARGE",
143
+ INVALID_FILE_TYPE: "STORAGE_INVALID_FILE_TYPE",
144
+ QUOTA_EXCEEDED: "STORAGE_QUOTA_EXCEEDED",
145
+ PRESIGNED_URL_EXPIRED: "STORAGE_PRESIGNED_URL_EXPIRED",
146
+ } as const
147
+
148
+ export const PostgrestErrorCodes = {
149
+ /** JWT expired or missing */
150
+ JWT_EXPIRED: "PGRST301",
151
+ /** No permission — RLS policy denied access */
152
+ PERMISSION_DENIED: "PGRST302",
153
+ /** Requested resource not found */
154
+ NOT_FOUND: "PGRST116",
155
+ /** Multiple rows returned when single expected */
156
+ MULTIPLE_ROWS: "PGRST116",
157
+ /** Schema cache miss — PostgREST needs reload */
158
+ SCHEMA_CACHE_MISS: "PGRST204",
159
+ /** Foreign key violation */
160
+ FK_VIOLATION: "PGRST23503",
161
+ /** Unique constraint violation */
162
+ UNIQUE_VIOLATION: "PGRST23505",
163
+ /** Not-null constraint violation */
164
+ NOT_NULL_VIOLATION: "PGRST23502",
165
+ /** Check constraint violation */
166
+ CHECK_VIOLATION: "PGRST23514",
167
+ /** Invalid input syntax */
168
+ INVALID_INPUT: "PGRST22P02",
169
+ /** Undefined table */
170
+ UNDEFINED_TABLE: "PGRST42P01",
171
+ /** Undefined column */
172
+ UNDEFINED_COLUMN: "PGRST42703",
173
+ } as const
174
+
175
+ export const RealtimeErrorCodes = {
176
+ /** WebSocket connection failed */
177
+ CONNECTION_FAILED: "REALTIME_CONNECTION_FAILED",
178
+ /** Subscription denied by RLS or auth */
179
+ SUBSCRIPTION_DENIED: "REALTIME_SUBSCRIPTION_DENIED",
180
+ /** Channel error from server */
181
+ CHANNEL_ERROR: "REALTIME_CHANNEL_ERROR",
182
+ /** Connection limit exceeded (429-equivalent for WS) */
183
+ CONNECTION_LIMIT: "REALTIME_CONNECTION_LIMIT",
184
+ /** Heartbeat timeout — server unresponsive */
185
+ HEARTBEAT_TIMEOUT: "REALTIME_HEARTBEAT_TIMEOUT",
186
+ } as const
187
+
188
+ export const NetworkErrorCodes = {
189
+ TIMEOUT: "NETWORK_TIMEOUT",
190
+ CONNECTION_REFUSED: "NETWORK_CONNECTION_REFUSED",
191
+ DNS_FAILURE: "NETWORK_DNS_FAILURE",
192
+ } as const
193
+
194
+ /** Union of all error code constant objects for programmatic access. */
195
+ export const ErrorCodes = {
196
+ Auth: AuthErrorCodes,
197
+ Postgrest: PostgrestErrorCodes,
198
+ Storage: StorageErrorCodes,
199
+ Realtime: RealtimeErrorCodes,
200
+ Network: NetworkErrorCodes,
201
+ } as const